always hit the DB to ensure we have the latest datums
This commit is contained in:
parent
49cf806724
commit
1edc72061e
2 changed files with 16 additions and 1 deletions
9
run.py
Normal file → Executable file
9
run.py
Normal file → Executable file
|
@ -10,3 +10,12 @@ import requests
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
|
||||||
cfg = json.load(open('meta.json'))
|
cfg = json.load(open('meta.json'))
|
||||||
|
|
||||||
|
db = mysql.connector.connect(user=cfg['dbuser'], password=cfg['dbpass'], database=cfg['dbname'])
|
||||||
|
c = db.cursor()
|
||||||
|
dc = db.cursor(dictionary=True)
|
||||||
|
|
||||||
|
dc.execute("SELECT * FROM data")
|
||||||
|
for row in dc.fetchall():
|
||||||
|
print(row)
|
||||||
|
|
8
web.py
8
web.py
|
@ -56,6 +56,12 @@ def main():
|
||||||
@app.route('/home')
|
@app.route('/home')
|
||||||
def home():
|
def home():
|
||||||
if 'acct' in session:
|
if 'acct' in session:
|
||||||
|
dc.execute("SELECT * FROM data WHERE username LIKE %s AND instance LIKE %s", (session['username'], session['instance']))
|
||||||
|
#TODO: if this fails, redirect to /logout
|
||||||
|
data = dc.fetchone()
|
||||||
|
for item in ['username', 'instance', 'avi', 'secret', 'client_id', 'client_secret', 'cc', 'ccavi']:
|
||||||
|
session[item] = data[item]
|
||||||
|
|
||||||
if 'cc' not in session:
|
if 'cc' not in session:
|
||||||
session['cc'] = "None"
|
session['cc'] = "None"
|
||||||
if session['cc'] == "None" or 'ccavi' not in session:
|
if session['cc'] == "None" or 'ccavi' not in session:
|
||||||
|
@ -66,7 +72,6 @@ def home():
|
||||||
session['cc'] = cc[0]
|
session['cc'] = cc[0]
|
||||||
session['ccavi'] = cc[1]
|
session['ccavi'] = cc[1]
|
||||||
|
|
||||||
|
|
||||||
if 'last_avi_update' not in session or session['last_avi_update'] + (24 * 60 * 60) < time.time():
|
if 'last_avi_update' not in session or session['last_avi_update'] + (24 * 60 * 60) < time.time():
|
||||||
#avatars haven't been updated for over 24 hours, update them now
|
#avatars haven't been updated for over 24 hours, update them now
|
||||||
client = Mastodon(client_id=session['client_id'], client_secret=session['client_secret'], access_token=session['secret'], api_base_url=session['instance'])
|
client = Mastodon(client_id=session['client_id'], client_secret=session['client_secret'], access_token=session['secret'], api_base_url=session['instance'])
|
||||||
|
@ -233,6 +238,7 @@ def ccc_c():
|
||||||
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, time_between_checks = %s, last_check = %s WHERE username = %s AND instance = %s", (session['cc'], session['ccavi'], session['cctemp']['latest_post'], 1, 0, session['username'], session['instance']))
|
c.execute("UPDATE data SET cc = %s, ccavi = %s, latest_post = %s, time_between_checks = %s, last_check = %s WHERE username = %s AND instance = %s", (session['cc'], session['ccavi'], session['cctemp']['latest_post'], 1, 0, session['username'], session['instance']))
|
||||||
|
db.commit()
|
||||||
del session['cctemp']
|
del session['cctemp']
|
||||||
return redirect('/cc_connect/complete')
|
return redirect('/cc_connect/complete')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue