Last active
October 8, 2017 23:49
-
-
Save codl/4e4b33f122d7469a4e4a798ee43ce6c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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