diff --git a/.gitignore b/.gitignore index 6a18ad4..0cecb81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +config.json + # ---> Python # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/config.json.sample b/config.json.sample new file mode 100644 index 0000000..1d27811 --- /dev/null +++ b/config.json.sample @@ -0,0 +1,3 @@ +{ + "site":"fedi.lynnesbian.space" +} \ No newline at end of file diff --git a/login.py b/login.py new file mode 100644 index 0000000..4198f49 --- /dev/null +++ b/login.py @@ -0,0 +1,25 @@ +scopes = ["read:statuses", "read:accounts", "read:follows", "write:statuses"] +cfg = json.load(open('config.json', 'r')) + +if "client" not in cfg: + print("No client credentials, registering application") + client_id, client_secret = Mastodon.create_app("lynnegle-assistant", + api_base_url=cfg['site'], + scopes=scopes, + website="https://git.lynnesbian.space/lynnesbian/lynnegle-assistant") + + cfg['client'] = { + "id": client_id, + "secret": client_secret + } + +if "secret" not in cfg: + print("No user credentials, logging in") + client = Mastodon(client_id = cfg['client']['id'], + client_secret = cfg['client']['secret'], + api_base_url=cfg['site']) + + print("Open this URL: {}".format(client.auth_request_url(scopes=scopes))) + cfg['secret'] = client.log_in(code=input("Secret: "), scopes=scopes) + +json.dump(cfg, open("config.json", "w+")) \ No newline at end of file diff --git a/main.py b/main.py index 8821c0d..9cd17b0 100755 --- a/main.py +++ b/main.py @@ -1,33 +1,20 @@ #!/usr/bin/env python3 + +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, +# You can obtain one at http://mozilla.org/MPL/2.0/. + import requests from mastodon import Mastodon import json -scopes = ["read:statuses", "read:accounts", "read:follows", "write:statuses"] -cfg = json.load(open('config.json', 'r')) +client = Mastodon( + client_id=cfg['client']['id'], + client_secret = cfg['client']['secret'], + access_token=cfg['secret'], + api_base_url=cfg['site']) -if "client" not in cfg: - print("No client credentials, registering application") - client_id, client_secret = Mastodon.create_app("lynnegle-assistant", - api_base_url=cfg['site'], - scopes=scopes, - website="https://github.com/Lynnesbian/mstdn-ebooks") - - cfg['client'] = { - "id": client_id, - "secret": client_secret - } - -if "secret" not in cfg: - print("No user credentials, logging in") - client = Mastodon(client_id = cfg['client']['id'], - client_secret = cfg['client']['secret'], - api_base_url=cfg['site']) - - print("Open this URL: {}".format(client.auth_request_url(scopes=scopes))) - cfg['secret'] = client.log_in(code=input("Secret: "), scopes=scopes) - -json.dump(cfg, open("config.json", "w+")) kind = 'general' if kind == 'images':