-
Notifications
You must be signed in to change notification settings - Fork 0
/
epg.py
executable file
·87 lines (70 loc) · 2.52 KB
/
epg.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
74
75
76
77
78
79
80
81
82
83
# -*- coding: utf-8 -*-
import client
import json
import epgrepo
#import channelrepo
import model
from datetime import datetime, timedelta
import control
apiUrl = 'https://webapi.toya.net.pl/v1/tv/guide/'
programUrl = apiUrl + 'program/'
detailUrl = apiUrl + 'programInfo/'
date_pattern = '%Y-%m-%d %H:%M:%S'
class GetInstance:
def __init__(self):
epglist = []
#repo = epgrepo.Repository(control.profile + control.db)
# dt = datetime.now()
#epgs = repo.findAfterStartBeforeEnd()
#for e in epgs:
# print(e)
# repo.cretetable(True)
# repo.close()
# dt = datetime.now()
# next = dt + timedelta(days=1)
# self.epg('57', dt)
def epg(self, num, dt):
epgs = []
dateStr = str(dt.date())
resp = client.requestJson(programUrl + num + '?date=' + dateStr)
epgData = json.loads(resp)['data'][num]
for epg in epgData:
if 'empty' not in epg['title']:
duration = int(epg['duration'])
start = epg['on_air_at']
descr = epg['short_description']
catgory = epg['category']
end = datetime.strptime(start, date_pattern) + timedelta(minutes=duration)
single = model.EPG(epg['id'], epg['title'], descr, None, catgory, start, end, duration, num, None, False)
epgs.append(single)
repo = epgrepo.Repository(control.profile + control.db)
repo.saveall(epgs)
repo.close()
def detail(self, epg):
try:
resp = client.requestJson(detailUrl + epg.id)
epgDetail = json.loads(resp)['data']
country = epgDetail['country']
long_description = epgDetail['long_description']
data = epgDetail['data']
epgData = json.loads(data)
if 'directedBy' in epgData:
directedBy = epgData['directedBy']
if 'cast' in epgData:
allCats = ''
first = True
for cast in epgData['cast']:
if first:
allCats += cast
first = False
else:
allCats += ', ' + cast
original_title = epgDetail['original_title']
epg.longdesc = long_description
except Exception as e:
print('EPG Detail Exception: ' + str(e))
epg.detail = True
return epg
if __name__ == '__main__':
EPG = GetInstance()
# EPG.epg()