Browse Source

ask user for authentication details

master
Lynne Megido 8 months ago
parent
commit
55c0733a40
Signed by: Lynne <thecoolone3@gmail.com> GPG Key ID: FB7B970303ACE499
2 changed files with 61 additions and 1 deletions
  1. 2
    1
      .gitignore
  2. 59
    0
      main.py

+ 2
- 1
.gitignore View File

@@ -1 +1,2 @@
/__pycache__/
/__pycache__/
config.json

+ 59
- 0
main.py View File

@@ -1 +1,60 @@
#!/usr/bin/env python3
from mastodon import Mastodon
import twitter

import sqlite3, json

cfg = {
"cw":None,
"mark_sensitive":True
}
try:
j = json.load(open("config.json"))
for key, value in j.items():
cfg[key] = value
except:
print("No config.json, using default configuration")

scopes = ["read:accounts", "write:statuses"]

if "client" not in cfg:
print("No application info -- registering application with {}".format(cfg['site']))
client_id, client_secret = Mastodon.create_app("Twitter Image Poster",
api_base_url=cfg['site'],
scopes=scopes,
website="https://git.lynnesbian.space/lynnesbian/Twitter_Image_Poster")

cfg['client'] = {
"id": client_id,
"secret": client_secret
}

if "secret" not in cfg:
print("No user credentials -- logging in to {}".format(cfg['site']))
client = Mastodon(client_id = cfg['client']['id'],
client_secret = cfg['client']['secret'],
api_base_url=cfg['site'])

print("Open this URL and authenticate to give Twitter Image Poster access to your bot's account: {}".format(client.auth_request_url(scopes=scopes)))
cfg['secret'] = client.log_in(code=input("Secret: "), scopes=scopes)

if "twitter" not in cfg:
print("No Twitter credentials")
print("Please create a Twitter app by using this page: https://developer.twitter.com/en/apps/create")
cfg['twitter'] = {
"consumer_key": None,
"consumer_secret": None,
"access_token_key": None,
"access_token_secret": None
}
for i in cfg['twitter'].keys():
cfg['twitter'][i] = input("{}: ".format(i))

json.dump(cfg, open("config.json", "w+"))

client = Mastodon(
client_id=cfg['client']['id'],
client_secret = cfg['client']['secret'],
access_token=cfg['secret'],
api_base_url=cfg['site'])


Loading…
Cancel
Save