summaryrefslogtreecommitdiff
path: root/app.py
blob: f3c061849f022a92f7d8cea15efa94a3a32b5a14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import json
from typing import List

from flask import Flask, render_template, abort

from json_serializable import JsonSerializable, from_json

app = Flask(__name__)


class Project(JsonSerializable):
    name: str
    description: str
    link: str


try:
    with open('projects.json') as handle:
        project_data: List[Project] = from_json(json.load(handle), List[Project])
except:
    project_data = []


@app.route('/projects/<project_name>')
def projects(project_name):
    matches = [project for project in project_data if project.name.lower() == project_name.lower()]
    if len(matches) == 0:
        abort(404)
    if len(matches) > 1:
        abort(500)
    return render_template('project.html', project=matches[0])


@app.route('/')
def hello_world():
    return render_template('index.html')


if __name__ == '__main__':
    app.run(port=80)