diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ae4d895 --- /dev/null +++ b/LICENSE @@ -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 + +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. diff --git a/datentrog.py b/datentrog.py index ba04da8..53cd4ef 100755 --- a/datentrog.py +++ b/datentrog.py @@ -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' % ( - bottle.request.urlparts.scheme, - bottle.request.urlparts.netloc, - route) + return "%s://%s/%s" % ( + bottle.request.urlparts.scheme, + bottle.request.urlparts.netloc, + 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()