From 959df2c8e912257882ecae4a2693028368ee2bd4 Mon Sep 17 00:00:00 2001 From: Terence Eden Date: Thu, 17 Nov 2022 09:53:34 +0000 Subject: [PATCH] Add status viewer --- README.md | 10 +++++++++- status.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 status.py diff --git a/README.md b/README.md index 9ba74d2..13d9a99 100644 --- a/README.md +++ b/README.md @@ -16,4 +16,12 @@ Usage: `python3 threads.py https://your_mastodon.instance/@username@their.instance/1234` -⚠ Note! Large conversations may take a long time to retrieve from the API. \ No newline at end of file +⚠ Note! Large conversations may take a long time to retrieve from the API. + +## Status + +Pretty Prints (in colour!) all the data behind a status. + +Usage: + +`python3 status.py https://mastodon.social/@Edent/109358520333182101` \ No newline at end of file diff --git a/status.py b/status.py new file mode 100644 index 0000000..b241eec --- /dev/null +++ b/status.py @@ -0,0 +1,32 @@ +import config +from mastodon import Mastodon +from urllib.parse import urlparse +import argparse +from rich.pretty import pprint + +# Take a command line argument. e.g. python3 threads.py https://mastodon.example/@me@somewhere/1234 +parser = argparse.ArgumentParser(description='Display the data behind a Mastodon status.') +parser.add_argument('url', metavar='URl', type=str, help='A URl of a post on your instance of Mastodon') +args = parser.parse_args() +path = urlparse(args.url).path +path_list = path.split("/") +path_id = path_list[-1] + +if path_id.isdigit() : + # Status ID + # This is the ID from *your* instance + status_id = int(path_id) +else : + print("Hmmm... That doesn't look like a valid Mastodon Status URl.\n" + + "It should look like https://mastodon.example/@me@somewhere/1234\n" + + "The last part of the URl must be the status ID, which is a number." + ) + exit() + +# Set up access +mastodon = Mastodon( api_base_url=config.instance, access_token=config.access_token ) + +# Get the status +status = mastodon.status(status_id) + +pprint(status) \ No newline at end of file