A place to inform on the world wide web
https://hbbs.decentral1.se
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.7 KiB
67 lines
1.7 KiB
"""Flask server."""
|
|
|
|
from csv import DictReader
|
|
from os import listdir
|
|
from os.path import basename, dirname
|
|
from pathlib import Path
|
|
|
|
from flask import Flask, abort, render_template
|
|
from ruamel.yaml import YAML
|
|
|
|
app = Flask(__name__)
|
|
cwd = dirname(Path(__file__).absolute())
|
|
yaml = YAML()
|
|
|
|
|
|
def get_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 programmes
|
|
|
|
|
|
def get_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 collection
|
|
|
|
|
|
@app.route("/")
|
|
def about():
|
|
return render_template("about.html")
|
|
|
|
|
|
@app.route("/programmes")
|
|
def programmes():
|
|
programmes = get_programmes()
|
|
return render_template("programmes.html", programmes=programmes)
|
|
|
|
|
|
@app.route("/programme/<name>/")
|
|
def programme(name):
|
|
cleaned_name = name.replace("-", " ").lower()
|
|
programmes = get_programmes()
|
|
for programme in programmes:
|
|
cleaned_programme = programme.get("title", "").lower()
|
|
if cleaned_name == cleaned_programme:
|
|
return render_template("programme.html", programme=programme)
|
|
abort(404, description="Programme not found")
|
|
|
|
|
|
@app.route("/collection")
|
|
def collection():
|
|
collection = get_collection()
|
|
return render_template("collection.html", collection=collection)
|
|
|
|
|
|
@app.route("/participate")
|
|
def participate():
|
|
return render_template("participate.html")
|
|
|