artbound_python/views.py (view raw)
1import json
2from flask import request, redirect, render_template
3from artbound_python import app
4from artbound_python.cache import last_updated, DB
5
6database = DB()
7
8@app.route('/', methods=['GET', 'POST'])
9def route_index():
10 if request.method == 'GET':
11 return render_template("index.html", last_updated=database.get_last_updated())
12
13 if (request.headers.get('Content-Type') != 'application/json'):
14 return 'Content-Type not supported. Please use "application/json".'
15
16 month = request.json["month"]
17 fanarts = database.get_fanarts(month)
18 return json.dumps(fanarts)
19
20@app.route('/update')
21def route_update():
22 database.update_database()
23 return redirect("/")