check for valid username, start working on download code

This commit is contained in:
Lynne Megido 2019-05-08 05:27:42 +10:00
parent d7e74db703
commit 78a97b6b41
Signed by: lynnesbian
GPG key ID: FB7B970303ACE499

28
main.py
View file

@ -62,17 +62,21 @@ if "accounts" not in cfg:
accounts = [] accounts = []
while i != "": while i != "":
i = input("User: ") i = input("User: ")
if not re.match("@(\w){1,15}$", i): if not re.match("@(\w){1,16}$", i):
if i == "":
print("Accounts to learn from: {}".format(", ".join(accounts)))
break
print("Invalid username") print("Invalid username")
continue continue
if i == "" and len(accounts) == 0: if i == "" and len(accounts) == 0:
print("You must enter at least one account") print("You must enter at least one account")
continue continue
print("Checking account...") print("Checking account...")
print(api.GetUser(screen_name=i)) try:
user = api.GetUser(screen_name=i)
accounts.append(i)
except:
print("Invalid username.")
# connect to database # connect to database
@ -81,11 +85,19 @@ db = sqlite3.connect("tip.db")
db.text_factory=str db.text_factory=str
c = db.cursor() 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") c.execute("CREATE TABLE IF NOT EXISTS `images` (post_id INT NOT NULL UNIQUE PRIMARY KEY, screen_name VARCHAR NOT NULL, image_url VARCHAR) WITHOUT ROWID")
db.commit() 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()) for acct in accounts:
last_tweet = c.execute("SELECT post_id FROM `images` WHERE user_id LIKE ? ORDER BY post_id DESC LIMIT 1", (acct,)).fetchone()
if last_tweet != None:
last_tweet = last_tweet[0]
else:
last_tweet = 0 # start from the first one
print("Downloading tweets from account {}, starting from {}".format(acct, last_tweet))
tl = api.GetUserTimeline(screen_name = acct, since_id = last_tweet, exclude_replies = True)
client = Mastodon( client = Mastodon(
client_id=cfg['client']['id'], client_id=cfg['client']['id'],