switched to mySQL backend

This commit is contained in:
Lynne Megido 2018-11-10 22:56:45 +10:00
parent 710634be73
commit 763d438c42
Signed by: lynnesbian
GPG key ID: FB7B970303ACE499
3 changed files with 10 additions and 6 deletions

View file

@ -1,5 +1,8 @@
{ {
"name":"Curious Greg", "name":"Curious Greg",
"website":"https://git.lynnesbian.space/lynnesbian/curious-greg", "website":"https://git.lynnesbian.space/lynnesbian/curious-greg",
"flask_key":"put a secure secret key here, and rename this file to 'meta.json'" "flask_key":"put a secure secret key here, and rename this file to 'meta.json'",
"dbuser":"curiousgreg",
"dbpass":"choose a good password for the mysql user and put it here",
"dbname":"curiousgreg"
} }

View file

@ -1,2 +1,3 @@
Flask==1.0.2 Flask==1.0.2
bcrypt==3.1.4 bcrypt==3.1.4
mysql-connector-python<9

8
web.py
View file

@ -4,18 +4,18 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import requests, sqlite3, json, hashlib import requests, json, hashlib, urllib
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 bcrypt import bcrypt
import urllib
cfg = json.load(open("meta.json")) cfg = json.load(open("meta.json"))
scopes = ["read:accounts", "write:statuses"] scopes = ["read:accounts", "write:statuses"]
db = sqlite3.connect("database.db") #TODO: switch to mysql so concurrency is possible db = mysql.connector.connect(user=cfg['dbuser'], password=cfg['dbpass'], database=cfg['dbname'])
c = db.cursor() c = db.cursor()
c.execute("CREATE TABLE IF NOT EXISTS `data` (username TEXT NOT NULL, instance TEXT NOT NULL, password TEXT NOT NULL, avi TEXT NOT NULL, secret TEXT NOT NULL, client_id TEXT NOT NULL, client_secret TEXT NOT NULL, cc TEXT, latest_post TEXT, latest_timestamp TEXT, time_between_checks INT)") c.execute("CREATE TABLE IF NOT EXISTS `data` (username TINYTEXT NOT NULL, instance TINYTEXT NOT NULL, password TINYTEXT NOT NULL, avi TEXT NOT NULL, secret TINYTEXT NOT NULL, client_id TINYTEXT NOT NULL, client_secret TINYTEXT NOT NULL, cc TINYTEXT, latest_post TINYTEXT, latest_timestamp TIMESTAMP, time_between_checks INT)")
app = Flask(cfg['name']) app = Flask(cfg['name'])
app.secret_key = cfg['flask_key'] app.secret_key = cfg['flask_key']