69 lines
1.7 KiB
Python
Executable File
69 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python
|
|
from flask import Flask, render_template, request
|
|
from pprint import pprint
|
|
import sqlite3
|
|
import os.path
|
|
|
|
|
|
def createDB():
|
|
if os.path.isfile('list.db'):
|
|
print("DB Exists")
|
|
else:
|
|
conn = sqlite3.connect('list.db')
|
|
c = conn.cursor()
|
|
c.execute('''CREATE TABLE LIST (
|
|
requester text, item text, quatity integer, gotten text)''')
|
|
conn.close()
|
|
|
|
|
|
def insTestData(c, conn, data):
|
|
c.execute("INSERT INTO list VALUES ('Tim', 'Memes', 100, 0)")
|
|
conn.commit()
|
|
|
|
|
|
def getData():
|
|
with sqlite3.connect('list.db') as conn:
|
|
c = conn.cursor()
|
|
res = c.execute("SELECT * FROM LIST")
|
|
data = res.fetchall()
|
|
pprint(data)
|
|
return data
|
|
|
|
|
|
def updateDB(req):
|
|
for item in req:
|
|
for value in item:
|
|
if value == "":
|
|
print("Null Detected Boi")
|
|
return
|
|
with sqlite3.connect('list.db') as conn:
|
|
c = conn.cursor()
|
|
print(req)
|
|
c.executemany('INSERT INTO LIST VALUES (?,?,?,?)', req)
|
|
conn.commit()
|
|
createDB()
|
|
|
|
app = Flask(__name__)
|
|
app.config['DEBUG'] = True
|
|
|
|
|
|
@app.route('/', methods=['POST', 'GET'])
|
|
def index():
|
|
if request.method == 'POST':
|
|
req = [(request.form['requester'], request.form['item'],
|
|
request.form['quantity'], "False")]
|
|
updateDB(req)
|
|
data = getData()
|
|
return render_template('index.html', data=data)
|
|
else:
|
|
data = getData()
|
|
return render_template('index.html', data=data)
|
|
|
|
#insTestData(2)
|
|
|
|
if __name__ == '__main__':
|
|
|
|
#ret = c.execute("SELECT * from LIST WHERE requester = 'Tim'")
|
|
#print(ret.fetchall())
|
|
app.run(host='0.0.0.0')
|