add license and reformat with black
This commit is contained in:
parent
49bbe12917
commit
9f469977ac
16
LICENSE
Normal file
16
LICENSE
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
This license does not apply to the heizhaus_logo* files and anything in
|
||||||
|
the static/bootstrap-3.4.1-dist directory
|
||||||
|
---
|
||||||
|
Copyright (c) 2021 Thomas Lindner <tom@dl6tom.de>
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
29
datentrog.py
29
datentrog.py
|
@ -9,7 +9,8 @@ import sqlite3
|
||||||
application = bottle.default_app()
|
application = bottle.default_app()
|
||||||
connection = sqlite3.connect("db.sqlite")
|
connection = sqlite3.connect("db.sqlite")
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute("""
|
cursor.execute(
|
||||||
|
"""
|
||||||
CREATE TABLE IF NOT EXISTS visitors (
|
CREATE TABLE IF NOT EXISTS visitors (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
event TEXT,
|
event TEXT,
|
||||||
|
@ -18,14 +19,16 @@ cursor.execute("""
|
||||||
address TEXT,
|
address TEXT,
|
||||||
contact TEXT
|
contact TEXT
|
||||||
);
|
);
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def url(route):
|
def url(route):
|
||||||
return '%s://%s/%s' % (
|
return "%s://%s/%s" % (
|
||||||
bottle.request.urlparts.scheme,
|
bottle.request.urlparts.scheme,
|
||||||
bottle.request.urlparts.netloc,
|
bottle.request.urlparts.netloc,
|
||||||
route)
|
route,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@application.get("/")
|
@application.get("/")
|
||||||
|
@ -58,7 +61,10 @@ def qr_get(event):
|
||||||
def qr_img_get(event):
|
def qr_img_get(event):
|
||||||
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=20)
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=20)
|
||||||
qr.add_data(url("event/" + event))
|
qr.add_data(url("event/" + event))
|
||||||
image = qr.make_image(image_factory=qrstyled.StyledPilImage, embeded_image_path="heizhaus_logo_square.png")
|
image = qr.make_image(
|
||||||
|
image_factory=qrstyled.StyledPilImage,
|
||||||
|
embeded_image_path="heizhaus_logo_square.png",
|
||||||
|
)
|
||||||
buffer = io.BytesIO()
|
buffer = io.BytesIO()
|
||||||
image.save(buffer, format="PNG")
|
image.save(buffer, format="PNG")
|
||||||
bottle.response.content_type = "image/png"
|
bottle.response.content_type = "image/png"
|
||||||
|
@ -79,19 +85,24 @@ def event_post(event):
|
||||||
data[field] = bottle.request.forms.get(field, "")
|
data[field] = bottle.request.forms.get(field, "")
|
||||||
data["success"] = data["success"] and data[field]
|
data["success"] = data["success"] and data[field]
|
||||||
if data["success"]:
|
if data["success"]:
|
||||||
cursor.execute("""
|
cursor.execute(
|
||||||
|
"""
|
||||||
INSERT INTO visitors (event, time, name, address, contact)
|
INSERT INTO visitors (event, time, name, address, contact)
|
||||||
VALUES (:event, datetime('now'), :name, :address, :contact);
|
VALUES (:event, datetime('now'), :name, :address, :contact);
|
||||||
""", data)
|
""",
|
||||||
|
data,
|
||||||
|
)
|
||||||
connection.commit()
|
connection.commit()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@application.get("/cleanup")
|
@application.get("/cleanup")
|
||||||
def cleanup():
|
def cleanup():
|
||||||
cursor.execute("""
|
cursor.execute(
|
||||||
|
"""
|
||||||
DELETE FROM visitors WHERE time < datetime('now', '-1 month');
|
DELETE FROM visitors WHERE time < datetime('now', '-1 month');
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue