more reliable method (hack) of checking if they've posted

This commit is contained in:
Lynne Megido 2018-11-15 11:12:20 +10:00
bovenliggende ba9b697a63
commit ab43960e61
Getekend door: lynnesbian
GPG sleutel-ID: FB7B970303ACE499

6
run.py
Bestand weergeven

@ -30,6 +30,7 @@ for row in dc.fetchall():
j = r.json()
if 'error' in j:
continue
posted = False
if len(j['posts']) > 0 and not (len(j['posts']) == 1 and int(j['posts'][0]['timestamp']) == int(row['latest_post'])):
#they've made some new posts, log in to masto
client = Mastodon(client_id=row['client_id'], client_secret=row['client_secret'], access_token=row['secret'], api_base_url=row['instance'])
@ -43,13 +44,16 @@ for row in dc.fetchall():
#this is the one we've already seen
continue
#if we get to this point, they've definitely made a post
posted = True
toot = "Curious Cat user {} asks: {}\n\nMy answer: {}\n\nhttps://curiouscat.me/{}/post/{}".format(sender, post['comment'], post['reply'], row['cc'], post['id']) #TODO: what if this is over 500 characters?
if settings['cw']:
client.status_post(toot, spoiler_text="Curious Cat post")
else:
client.status_post(toot)
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:
if not posted:
#we checked, and they haven't made a post
tbc = int(row['time_between_checks']) + 1
if tbc > int(cfg['max_time_between_checks']):