hbbs.decentral1.se/hbbs/server.py
2020-04-04 20:45:54 +02:00

47 lines
1.1 KiB
Python

"""Flask server."""
from csv import DictReader
from os import listdir
from os.path import basename, dirname, splitext
from pathlib import Path
from flask import Flask, render_template
from ruamel.yaml import YAML
app = Flask(__name__)
cwd = dirname(Path(__file__).absolute())
yaml = YAML()
@app.route("/")
def about():
return render_template("about.html")
@app.route("/programmes")
def programmes():
programmes = []
path = cwd / Path("static/programmes/")
for file in listdir(path):
with open(path / file, "r") as handle:
contents = handle.read()
loaded = yaml.load(contents)
programmes.append(loaded)
return render_template("programmes.html", programmes=programmes)
@app.route("/collection")
def collection():
collection = []
path = cwd / Path("static/csv/collection.csv")
with open(path, "r") as handle:
reader = DictReader(handle)
for row in reader:
collection.append(row)
return render_template("collection.html", collection=collection)
@app.route("/participate")
def participate():
return render_template("participate.html")