check for valid username, start working on download code
This commit is contained in:
parent
d7e74db703
commit
78a97b6b41
1 changed files with 20 additions and 8 deletions
28
main.py
28
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'],
|
||||
|
|
Reference in a new issue