Show prices through a minimal webapp

This commit is contained in:
2022-07-10 23:12:26 +02:00
parent 577ad61cf2
commit b190eebe46
8 changed files with 455 additions and 4 deletions

33
webapp.py Normal file
View File

@@ -0,0 +1,33 @@
from bottle import hook, request, route, run, static_file, view
import models
from models import Price
import os
# ----------------------------------------------------------------------
# Web application
@route("/")
@view("search_results")
def results_page():
query = Price.select().order_by(Price.date.desc())
results = list(query)
return dict(results=results)
@route("/static/<filename>")
def serve_static_file(filename):
project_dir = os.path.dirname(__file__)
static_root = os.path.join(project_dir, "static")
return static_file(filename, root=static_root)
@hook("before_request")
def connect_to_db():
models.db.connect()
@hook("after_request")
def close_db_connection():
models.db.close()