From cdfd3619f09655dc95db9e5b6ccb13513898a8d8 Mon Sep 17 00:00:00 2001 From: pancakes Date: Mon, 25 Nov 2024 00:07:01 +1000 Subject: [PATCH] Add account login function --- .gitignore | 1 + login.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 login.py diff --git a/.gitignore b/.gitignore index a6c57f5..f34e9d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +/accounts *.json diff --git a/login.py b/login.py new file mode 100644 index 0000000..13182c9 --- /dev/null +++ b/login.py @@ -0,0 +1,19 @@ +from mastodon import Mastodon +import os + + +if __name__ == "__main__": + username = input("username: ") + name = input("application name: ") + url = input("server url: ") + + if os.path.exists("accounts") and not os.path.isdir("accounts"): + print("accounts exists but isn't a directory") + exit(2) + elif not os.path.exists("accounts"): + os.mkdir("accounts") + + Mastodon.create_app(name, to_file=f"accounts/{username}.client.secret", api_base_url=url, user_agent="fedifeeds") + masto = Mastodon(f"accounts/{username}.client.secret") + print(masto.auth_request_url()) + masto.log_in(username, code=input("code: "), to_file=f"accounts/{username}.secret")