Commit 089259b6 authored by Julian Rother's avatar Julian Rother
Browse files

Changed configuration to flasks native solution

parent 35b8849e
......@@ -2,9 +2,10 @@
from flask import Flask, render_template, g
import mysql.connector
import sqlite3
import config
app = Flask(__name__)
config = app.config
# Row wrapper for sqlite
def dict_factory(cursor, row):
......@@ -17,15 +18,15 @@ def dict_factory(cursor, row):
return d
def query(operation, *params):
if config.db_engine == 'mysql':
if config['DB_ENGINE'] == 'mysql':
if 'db' not in g or not g.db.is_connected():
g.db = mysql.connector.connect(user=config.db_user, password=config.db_passwd, host=config.db_host, database=config.db_db)
g.db = mysql.connector.connect(user=config['MYSQL_USER'], password=config['MYSQL_PASSWD'], host=config['MYSQL_HOST'], database=config['MYSQL_DB'])
cur = g.db.cursor(dictionary=True)
cur.execute(operation.replace('?', '%s'), params)
return cur.fetchall()
elif config['DB_ENGINE'] == 'sqlite':
if 'db' not in g or not g.db.is_connected():
g.db = sqlite3.connect(config.db_file)
g.db = sqlite3.connect(config['SQLITE_DB'])
g.db.row_factory = dict_factory
cur = g.db.cursor()
cur.execute(operation, params)
......@@ -57,5 +58,4 @@ def play():
return render_template('play.html', active_page='play')
if __name__ == '__main__':
app.debug = True
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment