diff --git a/main.py b/main.py index 70f603c..c1103ab 100755 --- a/main.py +++ b/main.py @@ -62,17 +62,21 @@ if "accounts" not in cfg: accounts = [] while i != "": 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") 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)) - - - + try: + user = api.GetUser(screen_name=i) + accounts.append(i) + except: + print("Invalid username.") # connect to database @@ -81,11 +85,19 @@ 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") +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() -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_id=cfg['client']['id'],