From 49ff1386152cbd1cb431eed2a3b68efb5bfbe883 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Sun, 4 Dec 2022 18:16:36 +0100 Subject: [PATCH] wip --- toot/api.py | 8 ++++++++ toot/commands.py | 27 +++++++++++++++++++++++++++ toot/console.py | 13 +++++++++++++ 3 files changed, 48 insertions(+) diff --git a/toot/api.py b/toot/api.py index 5868430..b0ce01f 100644 --- a/toot/api.py +++ b/toot/api.py @@ -161,6 +161,14 @@ def fetch_status(app, user, id): return http.get(app, user, f"/api/v1/statuses/{id}").json() +def scheduled_status(app, user, id): + """ + Return a scheduled status by id + https://docs.joinmastodon.org/methods/scheduled_statuses/#get-one + """ + return http.get(app, user, f"/api/v1/scheduled_statuses/{id}").json() + + def scheduled_statuses(app, user): """ List scheduled statuses diff --git a/toot/commands.py b/toot/commands.py index d67f63a..4f3b9b0 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -77,6 +77,33 @@ def thread(app, user, args): print_timeline(thread) +def scheduled(app, user, args): + if args.id: + _show_scheduled(app, user, args.id) + else: + _list_scheduled(app, user) + + +def _list_scheduled(app, user): + statuses = api.scheduled_statuses(app, user) + for status in statuses: + print_scheduled(status) + + +def _show_scheduled(app, user, id): + status = api.scheduled_status(app, user, id) + print_scheduled_full(status) + + +def print_scheduled(status): + print_out(f'{status["id"]}') + + +def print_scheduled_full(status): + print_out(f'ID: {status["id"]}') + print_out(f'Scheduled at: {status["scheduled_at"]}') + + def post(app, user, args): if args.editor and not sys.stdin.isatty(): raise ConsoleError("Cannot run editor if not in tty.") diff --git a/toot/console.py b/toot/console.py index b9ff8c6..f04ddc0 100644 --- a/toot/console.py +++ b/toot/console.py @@ -317,6 +317,19 @@ READ_COMMANDS = [ arguments=timeline_args, require_auth=True, ), + Command( + name="scheduled", + description="Show pending scheduled statuses", + arguments=[ + (["id"], { + "help": "Optional status ID, to show a single scheduled " + "status, omit to list all", + "type": str, + "nargs": "?", + }) + ], + require_auth=True, + ), ] POST_COMMANDS = [