Skip to content

Instantly share code, notes, and snippets.

@eloquence
Created December 2, 2022 03:15
Show Gist options
  • Save eloquence/ce9d200db28ca13d1fd44d9487343885 to your computer and use it in GitHub Desktop.
Save eloquence/ce9d200db28ca13d1fd44d9487343885 to your computer and use it in GitHub Desktop.
import sys
from mastodon import Mastodon
from urllib.parse import urlparse
# Replace these with your own values
instance_url = 'https://fine-instance.social'
client_id = 'also called client key'
client_secret = 'yup yup'
access_token = 'uh huh'
# Create a Mastodon API client
mastodon = Mastodon(
client_id=client_id,
client_secret=client_secret,
access_token=access_token,
api_base_url=instance_url
)
# Get the command-line arguments
args = sys.argv[1:]
if len(args) == 1:
# Post a status update
mastodon.status_post(args[0])
elif len(args) == 2:
# Post a reply to an existing post
parsed_url = urlparse(args[0])
post_id = parsed_url.path.split('/')[-1]
mastodon.status_post(
args[1],
in_reply_to_id=post_id
)
else:
print('Usage: python post.py [URL] "Some status"')
print(' python post.py "Some status"')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment