-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsledovanitv-epgconvert.py
executable file
·48 lines (31 loc) · 1.37 KB
/
sledovanitv-epgconvert.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
#! /usr/bin/python
import json
import xml.etree.ElementTree as ET
import datetime
import os,time
epgfile = open('/dev/stdin','r').read()
epgdata = json.loads(epgfile)
tv=ET.Element('tv')
tv.attrib = {'generator-info-name': 'json2xml'}
local = time.strftime("%z")
for channeltext in epgdata['channels'] :
channel = ET.SubElement(tv, 'channel')
channel.attrib = {'id': channeltext}
displayname = ET.SubElement(channel,'display-name')
displayname.attrib = {'lang':'cs'}
displayname.text = channeltext
for channel in epgdata['channels'] :
for event in epgdata['channels'][channel]:
programme = ET.SubElement(tv,'programme')
l_start = datetime.datetime.strptime(event['startTime'], "%Y-%m-%d %H:%M")
l_stop = datetime.datetime.strptime(event['endTime'], "%Y-%m-%d %H:%M")
programme.attrib = { 'start': l_start.strftime("%Y%m%d%H%M%S ")+local, 'stop': l_stop.strftime("%Y%m%d%H%M%S ")+local, 'channel': channel }
title = ET.SubElement(programme, 'title')
title.text = event['title']
title.attrib = {'lang': 'cs'}
desc = ET.SubElement(programme, 'desc')
desc.text = event['description']
desc.attrib = {'lang': 'cs'}
date = ET.SubElement(programme, 'date')
date.text = l_start.strftime("%Y%m%d")
ET.dump(tv)