working run.py!

このコミットが含まれているのは:
Lynne Megido 2018-11-13 21:52:19 +10:00
コミット df1e73d271
署名者: lynnesbian
GPGキーID: FB7B970303ACE499

13
run.py
ファイルの表示

@ -18,6 +18,7 @@ dc = db.cursor(dictionary=True)
dc.execute("SELECT * FROM data")
for row in dc.fetchall():
print(row['cc'])
settings = json.loads(row['settings'])
t = int(time.time())
next_check = row['last_check'] + row['time_between_checks'] * 60
if next_check <= t:
@ -26,7 +27,7 @@ for row in dc.fetchall():
if row['cc'] != "None" and row['cc'] != None:
r = requests.get("https://curiouscat.me/api/v2/profile?username={}&count=100&min_timestamp={}".format(row['cc'], row['latest_post']))
j = r.json()
if len(j['posts'] > 0):
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'])
for post in j['posts']:
@ -35,7 +36,15 @@ for row in dc.fetchall():
else:
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']) #TODO: what if this is over 500 characters?
if int(post['timestamp']) == int(row['latest_post']):
#this is the one we've already seen
continue
toot = "Curious cat question from {}: \"{}\"\nMy 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?
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:
#we checked, and they haven't made a post