53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
from flask import Blueprint, render_template, request, g
|
|
from datetime import datetime, date
|
|
import sqlite3
|
|
|
|
|
|
keep = Blueprint('keep', __name__,template_folder='templates')
|
|
|
|
def get_db():
|
|
db = getattr(g, "_database", None)
|
|
if db is None:
|
|
db = g._database = sqlite3.connect("app/db/keepalive.db")
|
|
return db
|
|
|
|
@keep.route('/keepalive/')
|
|
def dispkeepalive():
|
|
conn = get_db()
|
|
c = conn.cursor()
|
|
items_from_db = c.execute("""SELECT
|
|
i.id, i.location, i.time, i.date
|
|
FROM
|
|
keepalive2 AS i
|
|
ORDER BY i.id DESC
|
|
""")
|
|
#db_teardown(keep)
|
|
items = []
|
|
for row in items_from_db:
|
|
item = {
|
|
"id": row[0],
|
|
"location": row[1],
|
|
"time": row[2],
|
|
"date": row[3]
|
|
}
|
|
items.append(item)
|
|
|
|
return render_template("keepaliveshowpage.html", items=items)
|
|
|
|
|
|
@keep.route('/<location>/', methods=["POST"])
|
|
def getalive(location):
|
|
if request.method == "POST":
|
|
conn = get_db()
|
|
c = conn.cursor()
|
|
c.execute("""INSERT INTO keepalive2
|
|
(location, date, time)
|
|
VALUES (?,?,?)""",
|
|
(
|
|
location,
|
|
date.today().strftime("%m/%d/%y"),
|
|
datetime.now().strftime("%H:%M:%S")
|
|
)
|
|
)
|
|
conn.commit()
|
|
return location |