58 lines
1.3 KiB
Python
58 lines
1.3 KiB
Python
from flask import Flask, render_template, request, redirect, url_for, jsonify
|
|
import sqlite3
|
|
|
|
# create table orders (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, remark TEXT, created_at datetime default current_timestamp, status text default "besteld");
|
|
|
|
# c = conn.cursor()
|
|
# Create table
|
|
# c.execute('''CREATE TABLE order
|
|
# (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, remark TEXT)''')
|
|
# conn.commit()
|
|
# conn.close()
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
def execute_query(query):
|
|
conn = sqlite3.connect('user.db')
|
|
c = conn.cursor()
|
|
|
|
print(f"{query=}")
|
|
results = []
|
|
|
|
# Insert a row of data
|
|
try:
|
|
c.execute(query)
|
|
results = c.fetchall()
|
|
except:
|
|
print("An sql execute error occured")
|
|
|
|
# Save (commit) the changes
|
|
conn.commit()
|
|
|
|
# We can also close the connection if we are done with it.
|
|
# Just be sure any changes have been committed or they will be lost.
|
|
conn.close()
|
|
return results
|
|
|
|
|
|
|
|
pancake_statuses = ["besteld", "aan_het_bakken", "klaar"]
|
|
|
|
|
|
@app.route("/")
|
|
def home():
|
|
return render_template("home.html")
|
|
|
|
|
|
@app.route("/execute", methods=["POST"])
|
|
def execute():
|
|
content = request.json
|
|
print("Query : ", content)
|
|
response = execute_query(content["lecode"])
|
|
return jsonify(response)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run()
|