-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
54 lines (42 loc) · 1.37 KB
/
main.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Future additions: comments
https://api.vrv.co/talkbox/guestbooks/G4VUQMQGW/comments?page=1&page_size=50
Comments are in reverse chronological order!"""
from generators import generate_series_feed, generate_season_feed
from api import api
from flask import Flask, render_template, request, redirect, url_for
from flask_caching import Cache
THREE_HOURS = 60 * 60 * 3
app = Flask(__name__)
cache = Cache(app, config={'CACHE_TYPE': 'SimpleCache'})
@app.route("/")
def index():
return render_template("index.html")
@app.route('/lookup')
def lookup():
return redirect(
url_for(
request.args.get("type"),
id=request.args.get("id"),
)
)
@app.route("/season_preview")
def season_preview():
series_id = request.args.get("id")
series = api.get_series(series_id)
seasons = api.get_seasons(series_id)
season_id_tuples = map(
lambda x: (x["title"], x["id"]),
seasons["items"]
)
return render_template("seasons.html", title=series["title"], seasons=season_id_tuples)
@app.route("/series/<id>")
@cache.cached(timeout=THREE_HOURS)
def series(id: str):
feed = generate_series_feed(id)
return app.response_class(feed.rss(), mimetype='application/rss+xml')
@app.route("/season/<id>")
@cache.cached(timeout=THREE_HOURS)
def season(id: str):
feed = generate_season_feed(id)
return app.response_class(feed.rss(), mimetype='application/rss+xml')
app.run(host='0.0.0.0', port=8080)