1
0
mirror of https://github.com/Adam-Ant/QuotesDB synced 2024-12-20 11:34:35 +00:00

Small restructure, add initial SQL set up and related SQL file

This commit is contained in:
Adam Dodman 2017-10-03 23:27:51 +01:00
parent fd8e17926e
commit 679a2d872e
2 changed files with 13 additions and 6 deletions

View File

@ -1,7 +1,9 @@
CREATE TABLE Users (
uid int NOT NULL AUTO_INCREMENT PRIMARY KEY,
user varchar(255) NOT NULL,
realname varchar(255) NOT NULL
uid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
user VARCHAR(255) NOT NULL,
realname VARCHAR(255) NOT NULL,
password VARCHAR(255),
isadmin BIT
);
CREATE TABLE Quotes (

11
main.py
View File

@ -8,8 +8,6 @@ pp = pprint.PrettyPrinter(indent=4)
app = Flask(__name__)
app.secret_key = rand(24)
# Thank you based StackOverflow
def cleanup_string(text):
text = text.encode("ascii", "replace").decode()
@ -26,7 +24,13 @@ def mysql_do(query):
db.close()
return data
userdb = mysql_do("SELECT * FROM Users")
def app_init():
mysql_do("CREATE TABLE IF NOT EXISTS Users ( uid INT NOT NULL AUTO_INCREMENT PRIMARY KEY, user VARCHAR(255) NOT NULL, realname VARCHAR(255) NOT NULL, password VARCHAR(255), isadmin BIT );")
mysql_do("CREATE TABLE IF NOT EXISTS Quotes ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, quote VARCHAR(2048) NOT NULL, date VARCHAR(255) NOT NULL, user INT NOT NULL, context VARCHAR(8000), FOREIGN KEY (user) REFERENCES Users(uid) );")
app.secret_key = rand(24)
global userdb
userdb = mysql_do("SELECT * FROM Users")
@app.route("/")
def index():
@ -109,4 +113,5 @@ def utility_processor():
return dict(uid_to_user=uid_to_user)
if __name__ == "__main__":
app_init()
app.run(host="0.0.0.0", debug=True)