diff --git a/.gitignore b/.gitignore index 00983fe..c574e7d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/__pycache__/ \ No newline at end of file +/__pycache__/ +config.json diff --git a/main.py b/main.py index e5a0d9b..8ec6529 100644 --- a/main.py +++ b/main.py @@ -1 +1,60 @@ #!/usr/bin/env python3 +from mastodon import Mastodon +import twitter + +import sqlite3, json + +cfg = { + "cw":None, + "mark_sensitive":True +} +try: + j = json.load(open("config.json")) + for key, value in j.items(): + cfg[key] = value +except: + print("No config.json, using default configuration") + +scopes = ["read:accounts", "write:statuses"] + +if "client" not in cfg: + print("No application info -- registering application with {}".format(cfg['site'])) + client_id, client_secret = Mastodon.create_app("Twitter Image Poster", + api_base_url=cfg['site'], + scopes=scopes, + website="https://git.lynnesbian.space/lynnesbian/Twitter_Image_Poster") + + cfg['client'] = { + "id": client_id, + "secret": client_secret + } + +if "secret" not in cfg: + print("No user credentials -- logging in to {}".format(cfg['site'])) + client = Mastodon(client_id = cfg['client']['id'], + client_secret = cfg['client']['secret'], + api_base_url=cfg['site']) + + print("Open this URL and authenticate to give Twitter Image Poster access to your bot's account: {}".format(client.auth_request_url(scopes=scopes))) + cfg['secret'] = client.log_in(code=input("Secret: "), scopes=scopes) + +if "twitter" not in cfg: + print("No Twitter credentials") + print("Please create a Twitter app by using this page: https://developer.twitter.com/en/apps/create") + cfg['twitter'] = { + "consumer_key": None, + "consumer_secret": None, + "access_token_key": None, + "access_token_secret": None + } + for i in cfg['twitter'].keys(): + cfg['twitter'][i] = input("{}: ".format(i)) + +json.dump(cfg, open("config.json", "w+")) + +client = Mastodon( + client_id=cfg['client']['id'], + client_secret = cfg['client']['secret'], + access_token=cfg['secret'], + api_base_url=cfg['site']) +