add license and reformat with black

This commit is contained in:
Thomas Lindner 2021-11-10 22:17:21 +01:00
parent 49bbe12917
commit 9f469977ac
2 changed files with 38 additions and 11 deletions

16
LICENSE Normal file
View 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.

View file

@ -9,7 +9,8 @@ import sqlite3
application = bottle.default_app()
connection = sqlite3.connect("db.sqlite")
cursor = connection.cursor()
cursor.execute("""
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS visitors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
event TEXT,
@ -18,14 +19,16 @@ cursor.execute("""
address TEXT,
contact TEXT
);
""")
"""
)
def url(route):
return '%s://%s/%s' % (
return "%s://%s/%s" % (
bottle.request.urlparts.scheme,
bottle.request.urlparts.netloc,
route)
route,
)
@application.get("/")
@ -58,7 +61,10 @@ def qr_get(event):
def qr_img_get(event):
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=20)
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()
image.save(buffer, format="PNG")
bottle.response.content_type = "image/png"
@ -79,19 +85,24 @@ def event_post(event):
data[field] = bottle.request.forms.get(field, "")
data["success"] = data["success"] and data[field]
if data["success"]:
cursor.execute("""
cursor.execute(
"""
INSERT INTO visitors (event, time, name, address, contact)
VALUES (:event, datetime('now'), :name, :address, :contact);
""", data)
""",
data,
)
connection.commit()
return data
@application.get("/cleanup")
def cleanup():
cursor.execute("""
cursor.execute(
"""
DELETE FROM visitors WHERE time < datetime('now', '-1 month');
""")
"""
)
connection.commit()