-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mastodon_create_app.py
46 lines (35 loc) · 1.44 KB
/
mastodon_create_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Get credentials for the Mastodon API with Mastodon.py
Based on this gist by Allison Parrish
https://gist.github.com/aparrish/661fca5ce7b4882a8c6823db12d42d26
"""
import argparse
from mastodon import Mastodon # pip install Mastodon.py
def mastodon_create_app(
app_name: str, email: str, password: str, instance: str
) -> None:
client_id, client_secret = Mastodon.create_app(
app_name, scopes=["read", "write"], api_base_url=instance
)
print(f"mastodon_client_id: {client_id}")
print(f"mastodon_client_secret: {client_secret}")
api = Mastodon(client_id, client_secret, api_base_url=instance)
access_token = api.log_in(email, password, scopes=["read", "write"])
print(f"mastodon_access_token: {access_token}")
def main() -> None:
parser = argparse.ArgumentParser(
description="Get credentials for the Mastodon API with Mastodon.py",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("app_name", help="Your app name")
parser.add_argument("email", help="Email you used to create your bot's account")
parser.add_argument(
"password", help="Password you used to create your bot's account"
)
parser.add_argument(
"--instance", default="https://botsin.space", help="Mastodon instance"
)
args = parser.parse_args()
mastodon_create_app(args.app_name, args.email, args.password, args.instance)
if __name__ == "__main__":
main()