Compare commits

..

No commits in common. "4bbc6ab393016a93453802d45b8d9d5844df950a" and "0e5604af47829a57de415802d1810972cb62110c" have entirely different histories.

12
web.py
View file

@ -6,8 +6,7 @@
#TODO: ADD RETROSPRING SUPPORT! #TODO: ADD RETROSPRING SUPPORT!
import json, hashlib, urllib, time, re, random import requests, 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
@ -37,11 +36,10 @@ 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, last_check 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, 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']
@ -196,7 +194,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'] #only post new answers from this point onwards, rather than posting all the old ones "latest_post":j['posts'][0]['timestamp']
} }
return redirect('/cc_connect/confirm') return redirect('/cc_connect/confirm')
@ -204,7 +202,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') #TODO: don't allow people to spam this @app.route('/internal/ccc_b')
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
@ -231,7 +229,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, 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 WHERE username = %s AND instance = %s", (session['cc'], session['ccavi'], session['cctemp']['latest_post'], 1, session['username'], session['instance']))
return redirect('/cc_connect/complete') return redirect('/cc_connect/complete')
@app.route('/cc_connect/complete') @app.route('/cc_connect/complete')