diff --git a/meta.sample.json b/meta.sample.json index 6c05682..d5fc4b4 100644 --- a/meta.sample.json +++ b/meta.sample.json @@ -1,5 +1,8 @@ { "name":"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" } diff --git a/requirements.txt b/requirements.txt index a22d459..f4174a4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Flask==1.0.2 -bcrypt==3.1.4 \ No newline at end of file +bcrypt==3.1.4 +mysql-connector-python<9 \ No newline at end of file diff --git a/web.py b/web.py index 458a889..a881565 100755 --- a/web.py +++ b/web.py @@ -4,18 +4,18 @@ # 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/. -import requests, sqlite3, json, hashlib +import requests, json, hashlib, urllib from mastodon import Mastodon from flask import Flask, render_template, request, session, redirect, url_for +import mysql.connector import bcrypt -import urllib cfg = json.load(open("meta.json")) 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.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.secret_key = cfg['flask_key']