summaryrefslogtreecommitdiff
path: root/webapp.py
blob: ea958058550d59d16c940a7226b4fd85c94ce798 (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
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3

import logging

from flask import Flask, Response, request

from rss_types import RSSFeed
from rss import buildRSS
from zdf import zdf
from urldelta import get_page_delta

app = Flask(__name__)
app.secret_key = "NMcgoB.0wd+$.KVKj!F{3>U{%BBUVhL=7=5$:46rQH$Q{enCuU"


def rssResponse(data: RSSFeed):
    rss = buildRSS(data)
    response = Response(rss, mimetype="text/xml")
    response.headers["Access-Control-Allow-Origin"] = "*"
    return response


@app.route("/")
def main():
    return "this is sparta"


@app.errorhandler(404)
def not_found(e):
    return "Die angeforderte Seite konnte nicht gefunden werden."


@app.route("/zdf/<path:show_url>")
def fetch_zdf_show(show_url):
    if rss_feed := zdf(show_url):
        return rssResponse(rss_feed)
    return "Failed"


@app.route("/delta")
def website_delta():
    if url := request.args.get("url"):
        return rssResponse(get_page_delta(url))
    return "Failed"


if __name__ == "__main__":
    logging.basicConfig(filename="./main.log", level=logging.INFO)

    app.config["TEMPLATES_AUTO_RELOAD"] = True
    app.run(threaded=True)