2021-11-08 23:23:07 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import bottle
|
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
|
|
|
|
application = bottle.default_app()
|
|
|
|
connection = sqlite3.connect("db.sqlite")
|
|
|
|
cursor = connection.cursor()
|
|
|
|
cursor.execute("""
|
|
|
|
CREATE TABLE IF NOT EXISTS visitors (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
event TEXT,
|
|
|
|
time DATETIME,
|
|
|
|
name TEXT,
|
|
|
|
address TEXT,
|
|
|
|
contact TEXT
|
|
|
|
);
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
|
|
@application.get("/")
|
2021-11-09 03:38:04 +00:00
|
|
|
def root_get():
|
|
|
|
return bottle.static_file("new.html", root="static")
|
|
|
|
|
|
|
|
|
|
|
|
@application.get("/static/<file:path>")
|
|
|
|
def datentrog_get(file):
|
|
|
|
return bottle.static_file(file, root="static")
|
2021-11-08 23:23:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
@application.post("/")
|
|
|
|
def datentrog_post():
|
2021-11-09 03:38:04 +00:00
|
|
|
bottle.redirect("event/" + bottle.request.forms.get("event", ""))
|
|
|
|
|
|
|
|
|
|
|
|
@application.get("/event/<event>")
|
|
|
|
@bottle.view("datentrog.tpl")
|
|
|
|
def event_get(event):
|
|
|
|
return dict(event=event)
|
|
|
|
|
|
|
|
|
|
|
|
@application.post("/event/<event>")
|
|
|
|
@bottle.view("datentrog.tpl")
|
|
|
|
def event_post(event):
|
2021-11-08 23:23:07 +00:00
|
|
|
data = {"feedback": True, "success": True}
|
|
|
|
for field in ("event", "name", "address", "contact"):
|
|
|
|
data[field] = bottle.request.forms.get(field, "")
|
|
|
|
data["success"] = data["success"] and data[field]
|
|
|
|
if data["success"]:
|
|
|
|
cursor.execute("""
|
|
|
|
INSERT INTO visitors (event, time, name, address, contact)
|
|
|
|
VALUES (:event, datetime('now'), :name, :address, :contact);
|
|
|
|
""", data)
|
|
|
|
connection.commit()
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
@application.get("/cleanup")
|
|
|
|
def cleanup():
|
|
|
|
cursor.execute("""
|
|
|
|
DELETE FROM visitors WHERE time < datetime('now', '-1 month');
|
|
|
|
""")
|
|
|
|
connection.commit()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
bottle.run(host="0.0.0.0", port=8080)
|
|
|
|
else:
|
|
|
|
application.catchall = False
|