Compare commits
No commits in common. "df1e73d27110f4373e52dd7d3cc432085a716931" and "cb30496d6263c554dfb59f387331ec439c69bf30" have entirely different histories.
df1e73d271
...
cb30496d62
2 changed files with 5 additions and 14 deletions
13
run.py
13
run.py
|
@ -18,7 +18,6 @@ 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['cc'])
|
print(row['cc'])
|
||||||
settings = json.loads(row['settings'])
|
|
||||||
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:
|
||||||
|
@ -27,7 +26,7 @@ for row in dc.fetchall():
|
||||||
if row['cc'] != "None" and row['cc'] != None:
|
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']))
|
r = requests.get("https://curiouscat.me/api/v2/profile?username={}&count=100&min_timestamp={}".format(row['cc'], row['latest_post']))
|
||||||
j = r.json()
|
j = r.json()
|
||||||
if len(j['posts']) > 0 and not (len(j['posts']) == 1 and int(j['posts'][0]['timestamp']) == int(row['latest_post'])):
|
if len(j['posts'] > 0):
|
||||||
#they've made some new posts, log in to masto
|
#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'])
|
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']:
|
for post in j['posts']:
|
||||||
|
@ -36,15 +35,7 @@ for row in dc.fetchall():
|
||||||
else:
|
else:
|
||||||
sender = post['senderData']['username']
|
sender = post['senderData']['username']
|
||||||
|
|
||||||
if int(post['timestamp']) == int(row['latest_post']):
|
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?
|
||||||
#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']))
|
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:
|
else:
|
||||||
#we checked, and they haven't made a post
|
#we checked, and they haven't made a post
|
||||||
|
|
6
web.py
6
web.py
|
@ -193,7 +193,7 @@ def cc_connect():
|
||||||
|
|
||||||
@app.route('/internal/ccc_a', methods=['POST'])
|
@app.route('/internal/ccc_a', methods=['POST'])
|
||||||
def ccc_a(): #step one of curiouscat connection: retreive details
|
def ccc_a(): #step one of curiouscat connection: retreive details
|
||||||
r = requests.get("https://curiouscat.me/api/v2/profile?username={}&count=1".format(request.form['cc']))
|
r = requests.get("https://curiouscat.me/api/v2/profile?username={}".format(request.form['cc']))
|
||||||
j = r.json()
|
j = r.json()
|
||||||
if 'error' in j:
|
if 'error' in j:
|
||||||
return redirect('/cc_connect?invalid')
|
return redirect('/cc_connect?invalid')
|
||||||
|
@ -201,7 +201,7 @@ def ccc_a(): #step one of curiouscat connection: retreive details
|
||||||
"cc":j['userData']['username'],
|
"cc":j['userData']['username'],
|
||||||
"ccavi":j['userData']['avatar'],
|
"ccavi":j['userData']['avatar'],
|
||||||
"ccid":j['userData']['id'],
|
"ccid":j['userData']['id'],
|
||||||
"latest_post":j['posts'][0]['timestamp'] if len(j['posts']) != 0 else 0 #only post new answers from this point onwards, rather than posting all the old ones
|
"latest_post":j['posts'][0]['timestamp'] #only post new answers from this point onwards, rather than posting all the old ones
|
||||||
}
|
}
|
||||||
return redirect('/cc_connect/confirm')
|
return redirect('/cc_connect/confirm')
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ def ccc_c():
|
||||||
return redirect('/cc_connect/code?invalid')
|
return redirect('/cc_connect/code?invalid')
|
||||||
for item in ['cc', 'ccavi']:
|
for item in ['cc', 'ccavi']:
|
||||||
session[item] = session['cctemp'][item]
|
session[item] = session['cctemp'][item]
|
||||||
c.execute("UPDATE data SET cc = %s, ccavi = %s, latest_post = %s WHERE username = %s AND instance = %s", (session['cc'], session['ccavi'], session['cctemp']['latest_post'], session['username'], session['instance']))
|
c.execute("UPDATE data SET cc = %s, ccavi = %s, latest_post = %s, WHERE username = %s AND instance = %s", (session['cc'], session['ccavi'], session['cctemp']['latest_post'], session['username'], session['instance']))
|
||||||
db.commit()
|
db.commit()
|
||||||
del session['cctemp']
|
del session['cctemp']
|
||||||
return redirect('/cc_connect/complete')
|
return redirect('/cc_connect/complete')
|
||||||
|
|
Loading…
Reference in a new issue