moved login to separate file
This commit is contained in:
parent
9f0150ad3a
commit
449f245fe4
4 changed files with 41 additions and 24 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
||||||
|
config.json
|
||||||
|
|
||||||
# ---> Python
|
# ---> Python
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|
3
config.json.sample
Normal file
3
config.json.sample
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"site":"fedi.lynnesbian.space"
|
||||||
|
}
|
25
login.py
Normal file
25
login.py
Normal file
|
@ -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+"))
|
31
main.py
31
main.py
|
@ -1,33 +1,20 @@
|
||||||
#!/usr/bin/env python3
|
#!/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
|
import requests
|
||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
import json
|
import json
|
||||||
|
|
||||||
scopes = ["read:statuses", "read:accounts", "read:follows", "write:statuses"]
|
client = Mastodon(
|
||||||
cfg = json.load(open('config.json', 'r'))
|
client_id=cfg['client']['id'],
|
||||||
|
|
||||||
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'],
|
client_secret = cfg['client']['secret'],
|
||||||
|
access_token=cfg['secret'],
|
||||||
api_base_url=cfg['site'])
|
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'
|
kind = 'general'
|
||||||
if kind == 'images':
|
if kind == 'images':
|
||||||
|
|
Loading…
Reference in a new issue