Add status viewer

pages
Terence Eden 2022-11-17 09:53:34 +00:00
rodzic 1c76ca8b2c
commit 959df2c8e9
2 zmienionych plików z 41 dodań i 1 usunięć

Wyświetl plik

@ -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.
⚠ 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`

32
status.py 100644
Wyświetl plik

@ -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)