Add account login function

This commit is contained in:
pancakes 2024-11-25 00:07:01 +10:00
parent 5c65cab619
commit cdfd3619f0
No known key found for this signature in database
GPG key ID: ED53D426432B861B
2 changed files with 20 additions and 0 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/accounts
*.json

19
login.py Normal file
View file

@ -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")