Added DB stuffs
This commit is contained in:
parent
0671803dfe
commit
59a6e45cf2
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
env/
|
env/
|
||||||
|
list.db
|
||||||
|
|||||||
63
main.py
Executable file
63
main.py
Executable file
@ -0,0 +1,63 @@
|
|||||||
|
#!/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 real, gotten real)''')
|
||||||
|
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):
|
||||||
|
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'], request.form['gotten'])]
|
||||||
|
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()
|
||||||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
flask
|
||||||
24
templates/index.html
Normal file
24
templates/index.html
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<html>
|
||||||
|
<body style="background: #123456">
|
||||||
|
<h1>Shopping list </h1>
|
||||||
|
|
||||||
|
{% for res in data %}
|
||||||
|
{% for field in res %}
|
||||||
|
{{ field }}
|
||||||
|
{% endfor %}
|
||||||
|
<br/>
|
||||||
|
{% endfor %}
|
||||||
|
<form action="/" method="post">
|
||||||
|
<label>Who Dat?</label>
|
||||||
|
<input type="text" name='requester'/><br/>
|
||||||
|
<label>Watchu Want?</label>
|
||||||
|
<input type="text" name='item'/><br/>
|
||||||
|
<label>How Many?</label>
|
||||||
|
<input type="text" name='quantity'/><br/>
|
||||||
|
<label>Have we gotten it?</label>
|
||||||
|
<input type="text" name='gotten'/><br/>
|
||||||
|
<input type="submit"/>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user