omg
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
from flask import Flask, render_template, request, redirect, url_for, jsonify
|
from flask import Flask, render_template, request, redirect, url_for, jsonify
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
import re
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
pattern = re.compile(r"^(?:[01]\d|2[0-3]):[0-5]\d$") # Regex "XX:XX"
|
||||||
|
|
||||||
DB_PATH = "data.db"
|
DB_PATH = "data.db"
|
||||||
|
|
||||||
conn = sqlite3.connect(DB_PATH)
|
conn = sqlite3.connect(DB_PATH)
|
||||||
@@ -16,6 +19,11 @@ CREATE TABLE IF NOT EXISTS items (
|
|||||||
noshutdown INTEGER DEFAULT 0
|
noshutdown INTEGER DEFAULT 0
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
cursor.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS val (
|
||||||
|
default_time TEXT NOT NULL DEFAULT '21:00'
|
||||||
|
)
|
||||||
|
""")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
@@ -30,9 +38,10 @@ def mainpage():
|
|||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("SELECT name, time, noshutdown FROM items ORDER BY name")
|
cursor.execute("SELECT name, time, noshutdown FROM items ORDER BY name")
|
||||||
items = cursor.fetchall()
|
items = cursor.fetchall()
|
||||||
|
cursor.execute("SELECT default_time FROM val")
|
||||||
|
default_time = cursor.fetchone()
|
||||||
conn.close()
|
conn.close()
|
||||||
print(items)
|
return render_template('index.html', title='BS Shutdown', items=items, default_time=default_time)
|
||||||
return render_template('index.html', title='BS Shutdown', items=items)
|
|
||||||
|
|
||||||
@app.route('/submit', methods =['POST'])
|
@app.route('/submit', methods =['POST'])
|
||||||
def submit():
|
def submit():
|
||||||
@@ -45,6 +54,9 @@ def submit():
|
|||||||
return redirect(url_for("mainpage"))
|
return redirect(url_for("mainpage"))
|
||||||
if noshutdown == 1:
|
if noshutdown == 1:
|
||||||
time_value = 'None'
|
time_value = 'None'
|
||||||
|
if time_value != 'None':
|
||||||
|
if bool(pattern.match(time_value)) is not True:
|
||||||
|
return redirect(url_for("mainpage"))
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('SELECT 1 FROM items WHERE name = ?', (value,))
|
cursor.execute('SELECT 1 FROM items WHERE name = ?', (value,))
|
||||||
@@ -57,6 +69,18 @@ def submit():
|
|||||||
conn.close()
|
conn.close()
|
||||||
return redirect(url_for("mainpage"))
|
return redirect(url_for("mainpage"))
|
||||||
|
|
||||||
|
@app.route("/submit-default", methods=["POST"])
|
||||||
|
def submit_default():
|
||||||
|
time_value = request.form.get("time-select")
|
||||||
|
conn = get_db_connection()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
if bool(pattern.match(time_value)) is not True:
|
||||||
|
return redirect(url_for("mainpage"))
|
||||||
|
cursor.execute("UPDATE val SET default_time = ?", (time_value,))
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
return redirect(url_for("mainpage"))
|
||||||
|
|
||||||
@app.route("/delete", methods=["POST"])
|
@app.route("/delete", methods=["POST"])
|
||||||
def delete():
|
def delete():
|
||||||
value = request.form.get("item_name")
|
value = request.form.get("item_name")
|
||||||
|
|||||||
Reference in New Issue
Block a user