-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
73 lines (49 loc) · 1.63 KB
/
app.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from flask import Flask
from flask import render_template
import xml.etree.ElementTree as ET
import jinja2
from models.programme import Programme
from models.channelName import ChannelName
from models.tvGuide import TvGuide
import codecs
from datetime import datetime
import subprocess
# sudo apt install xmltv -y
# cd to folder where this file exists
#subprocess.call("sudo tv_grab_eu_xmltvse --config-file .xmltv/tv_grab_eu_xmltvse.conf --output tv.xml", shell=True)
tree = ET.parse('tv.xml')
root = tree.getroot()
# printNode(root)
# exit()
guide = TvGuide()
channelName_Id = {}
for child in root:
if child.tag != "channel":
continue
channelName_Id[child.attrib["id"]] = child.getchildren()[0].text
for child in root:
if child.tag != "programme":
continue
p = Programme(ChannelName(
channelName_Id[child.attrib["channel"]], child.attrib["channel"]), child.attrib["start"], child.attrib["stop"])
for c in child:
p.data[c.tag] = c.text.replace(" - ", " — ").replace(" ", " ")
guide.addProgram(p)
# print(p.data)
app = Flask(__name__)
templateLoader = jinja2.FileSystemLoader(searchpath="./templates/")
templateEnv = jinja2.Environment(loader=templateLoader)
TEMPLATE_FILE = "hello.html"
template = templateEnv.get_template(TEMPLATE_FILE)
def url_for(where, filename):
return filename
guideHtmlString = template.render(guide=guide, url_for=url_for)
f = codecs.open("guide.html", "w", "utf-8-sig")
f.write(guideHtmlString)
f.close()
@app.route('/')
def index():
return render_template('hello.html', guide=guide)
@app.route('/hello')
def hello():
return 'Hello, World'