Skip to content

Instantly share code, notes, and snippets.

@mneko22
Last active April 15, 2017 19:49
Show Gist options
  • Select an option

  • Save mneko22/3fa59e63026ae4d12d14ec2dc0f44941 to your computer and use it in GitHub Desktop.

Select an option

Save mneko22/3fa59e63026ae4d12d14ec2dc0f44941 to your computer and use it in GitHub Desktop.
mastodon.py toot sample for mstdn.jp
"""This is a test program."""
from mastodon import Mastodon
import os
CLIENT_ID = 'c9ce278f74a48920e487ca103ca2970f5e6bb6d54566f151bffb87ad84906303'
CLIENT_SECRET = '7ddd75db55213ed242b805459686df434d2335842d5855bc18eb0d7dc567f004'
API_SERVER = 'https://mstdn.jp/'
def init():
''' init '''
if os.path.isfile('pytooter_usercred.txt'):
with open('pytooter_usercred.txt', 'r') as token_file:
_user_token = token_file.readline().rstrip()
return Mastodon(client_id=CLIENT_ID, client_secret=CLIENT_SECRET,
api_base_url=API_SERVER, access_token=_user_token)
else:
mastodon = Mastodon(client_id=CLIENT_ID, client_secret=CLIENT_SECRET,
api_base_url=API_SERVER)
user_mail = input('user_email: ')
user_passwd = input('password: ')
mastodon.log_in(
user_mail,
user_password,
to_file='pytooter_usercred.txt'
)
return mastodon
def main():
''' toto '''
instance = init()
content = input("->")
instance.toot(content)
if __name__ == '__main__':
main()
Mastodon.py==1.0.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment