finished first version of run.py

This commit is contained in:
Lynne Megido 2018-11-13 20:58:07 +10:00
parent d1af18f0d2
commit f5f183b45b
Signed by: lynnesbian
GPG key ID: FB7B970303ACE499

13
run.py
View file

@ -17,10 +17,10 @@ dc = db.cursor(dictionary=True)
dc.execute("SELECT * FROM data") dc.execute("SELECT * FROM data")
for row in dc.fetchall(): for row in dc.fetchall():
print(row) print(row['cc'])
t = int(time.time()) t = int(time.time())
next_check = row['last_check'] + row['time_between_checks'] * 60 next_check = row['last_check'] + row['time_between_checks'] * 60
if next_check > t: if next_check <= t:
row['time_between_checks'] = cfg['min_time_between_checks'] row['time_between_checks'] = cfg['min_time_between_checks']
#time to check #time to check
if row['cc'] != "None" and row['cc'] != None: if row['cc'] != "None" and row['cc'] != None:
@ -35,5 +35,12 @@ for row in dc.fetchall():
else: else:
sender = post['senderData']['username'] sender = post['senderData']['username']
toot = "Curious cat question from {}: \"{}\"<br />My answer: {}\nView online at https://curiouscat.me/{}/post/{}".format(sender, post['comment'], post['reply'], row['cc'], post['id']) toot = "Curious cat question from {}: \"{}\"<br />My answer: {}\nView online at https://curiouscat.me/{}/post/{}".format(sender, post['comment'], post['reply'], row['cc'], post['id']) #TODO: what if this is over 500 characters?
c.execute("UPDATE data SET last_check = %s, time_between_checks = %s, latest_post = %s", (t, cfg['min_time_between_checks'], j['posts'][0]['timestamp']))
else:
#we checked, and they haven't made a post
tbc = int(row['time_between_checks']) + 1
if tbc > int(cfg['max_time_between_checks']):
tbc = cfg['max_time_between_checks']
c.execute("UPDATE data SET last_check = %s, time_between_checks = %s", (t, tbc))