Skip to content

Instantly share code, notes, and snippets.

@codl
Last active October 8, 2017 23:49
Show Gist options
  • Save codl/4e4b33f122d7469a4e4a798ee43ce6c1 to your computer and use it in GitHub Desktop.
Save codl/4e4b33f122d7469a4e4a798ee43ce6c1 to your computer and use it in GitHub Desktop.
import pickle
from mastodon import Mastodon
INSTANCE = 'http://localhost:3000'
with open('app_credentials.pickle', 'ab+') as f:
try:
f.seek(0)
(client_id, client_secret) = pickle.load(f)
except Exception:
(client_id, client_secret) = (
Mastodon.create_app(
'mastodon.py issue #95 test',
api_base_url=INSTANCE))
f.seek(0)
pickle.dump((client_id, client_secret), f)
api = Mastodon(client_id, client_secret, api_base_url=INSTANCE)
api.log_in(input('login: '), input('password: '))
with open('z.png', 'rb') as f:
media = api.media_post(f.read(), 'image/png')
print('Successfully uploaded media: {}'.format(media))
print('---')
status = api.status_post('toast (test poast)', media_ids=[media])
print('Successfully posted: {}'.format(media))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment