Compare commits

..

2 commits

Author SHA1 Message Date
4bbc6ab393
bug fixes and performance enhancements 2018-11-13 00:16:51 +10:00
0279b09690
changed DB schema *again* ugh 2018-11-12 23:39:52 +10:00

12
web.py
View file

@ -6,7 +6,8 @@
#TODO: ADD RETROSPRING SUPPORT! #TODO: ADD RETROSPRING SUPPORT!
import requests, json, hashlib, urllib, time, re, random import json, hashlib, urllib, time, re, random
import requests
from mastodon import Mastodon from mastodon import Mastodon
from flask import Flask, render_template, request, session, redirect, url_for from flask import Flask, render_template, request, session, redirect, url_for
import mysql.connector import mysql.connector
@ -36,10 +37,11 @@ dc = db.cursor(dictionary=True)
# | cc | tinytext | YES | | NULL | | # | cc | tinytext | YES | | NULL | |
# | ccavi | varchar(128) | YES | | https://lynnesbian.space/res/ceres/cc-smol.png | | # | ccavi | varchar(128) | YES | | https://lynnesbian.space/res/ceres/cc-smol.png | |
# | latest_post | tinytext | YES | | NULL | | # | latest_post | tinytext | YES | | NULL | |
# | last_check | tinytext | YES | | NULL | |
# | time_between_checks | int(11) | YES | | NULL | | # | time_between_checks | int(11) | YES | | NULL | |
# | settings | longtext | YES | | NULL | | # | settings | longtext | YES | | NULL | |
# +---------------------+--------------+------+-----+------------------------------------------------+-------+ # +---------------------+--------------+------+-----+------------------------------------------------+-------+
c.execute("CREATE TABLE IF NOT EXISTS `data` (username VARCHAR(64) NOT NULL, instance VARCHAR(128) NOT NULL, password TINYTEXT NOT NULL, avi TEXT NOT NULL, secret TINYTEXT NOT NULL, client_id VARCHAR(128) NOT NULL, client_secret TINYTEXT NOT NULL, cc TINYTEXT, ccavi VARCHAR(128) DEFAULT 'https://lynnesbian.space/res/ceres/cc-smol.png', latest_post TINYTEXT, time_between_checks INT, settings LONGTEXT, PRIMARY KEY(username, instance))") c.execute("CREATE TABLE IF NOT EXISTS `data` (username VARCHAR(64) NOT NULL, instance VARCHAR(128) NOT NULL, password TINYTEXT NOT NULL, avi TEXT NOT NULL, secret TINYTEXT NOT NULL, client_id VARCHAR(128) NOT NULL, client_secret TINYTEXT NOT NULL, cc TINYTEXT, ccavi VARCHAR(128) DEFAULT 'https://lynnesbian.space/res/ceres/cc-smol.png', latest_post TINYTEXT, last_check TINYTEXT, time_between_checks INT, settings LONGTEXT, PRIMARY KEY(username, instance))")
app = Flask(cfg['name']) app = Flask(cfg['name'])
app.secret_key = cfg['flask_key'] app.secret_key = cfg['flask_key']
@ -194,7 +196,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'] "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')
@ -202,7 +204,7 @@ def ccc_a(): #step one of curiouscat connection: retreive details
def cc_connect_confirm(): def cc_connect_confirm():
return render_template('cc_connect_confirm.html', bg="background-image:url('{}')".format(session['cctemp']['ccavi'])) return render_template('cc_connect_confirm.html', bg="background-image:url('{}')".format(session['cctemp']['ccavi']))
@app.route('/internal/ccc_b') @app.route('/internal/ccc_b') #TODO: don't allow people to spam this
def ccc_b(): def ccc_b():
session['cctemp']['challenge'] = random.randint(100000, 999999) session['cctemp']['challenge'] = random.randint(100000, 999999)
session.modified = True session.modified = True
@ -229,7 +231,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, time_between_checks = %s WHERE username = %s AND instance = %s", (session['cc'], session['ccavi'], session['cctemp']['latest_post'], 1, 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']))
return redirect('/cc_connect/complete') return redirect('/cc_connect/complete')
@app.route('/cc_connect/complete') @app.route('/cc_connect/complete')