Mastodon_Tools/status.py

34 wiersze
1.1 KiB
Python
Executable File

#!/usr/bin/env python
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)