check usernames, create database

This commit is contained in:
Lynne Megido 2019-02-27 13:38:10 +10:00
parent cd2a8f0d7b
commit d7e74db703
Signed by: lynnesbian
GPG key ID: FB7B970303ACE499

37
main.py
View file

@ -2,7 +2,7 @@
from mastodon import Mastodon from mastodon import Mastodon
import twitter import twitter
import sqlite3, json import sqlite3, json, re
cfg = { cfg = {
"cw":None, "cw":None,
@ -53,9 +53,44 @@ if "twitter" not in cfg:
json.dump(cfg, open("config.json", "w+")) json.dump(cfg, open("config.json", "w+"))
# log in to twitter
api = twitter.Api(**cfg['twitter'])
if "accounts" not in cfg:
print("Please specify the accounts you'd like Twitter Image Poster to learn from. Enter one account at a time formatted as '@user', followed by a blank line.")
i = None
accounts = []
while i != "":
i = input("User: ")
if not re.match("@(\w){1,15}$", i):
print("Invalid username")
continue
if i == "" and len(accounts) == 0:
print("You must enter at least one account")
continue
print("Checking account...")
print(api.GetUser(screen_name=i))
# connect to database
db = sqlite3.connect("tip.db")
db.text_factory=str
c = db.cursor()
c.execute("CREATE TABLE IF NOT EXISTS `images` (post_id INT NOT NULL UNIQUE PRIMARY KEY, user_id INT NOT NULL, image_url VARCHAR) WITHOUT ROWID")
db.commit()
last_tweet = c.execute("SELECT post_id FROM `images` WHERE user_id LIKE ? ORDER BY post_id DESC LIMIT 1", (f.id,)).fetchone()
print("Downloading tweets from {}".format())
client = Mastodon( client = Mastodon(
client_id=cfg['client']['id'], client_id=cfg['client']['id'],
client_secret = cfg['client']['secret'], client_secret = cfg['client']['secret'],
access_token=cfg['secret'], access_token=cfg['secret'],
api_base_url=cfg['site']) api_base_url=cfg['site'])