forked from pythcon/PlexTVChannel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateXMLTV.py
48 lines (39 loc) · 1.63 KB
/
generateXMLTV.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
import time
from datetime import datetime, timedelta
import temp_variables
def generateGuideData(myTvDirectory, myBackup, myShowDurations):
showCounter = 0
print("Generating Guide Data...This will take a few seconds")
# Replace time in xmltv files
## Need to do this after execution b/c script takes long to execute
f1 = open(myTvDirectory + 'temp_xmltv.xml', 'r')
if not myBackup:
f2 = open(myTvDirectory + 'xmltv.xml', 'w')
else:
f2 = open(myTvDirectory + 'xmltv1.xml', 'w')
# Wait for script to run on the minute (0 seconds)
timeObject = datetime.now()
myCurrentTime = int(timeObject.strftime("%S"))
while (myCurrentTime / 60) != 0:
timeObject = datetime.now()
myCurrentTime = int(timeObject.strftime("%S"))
continue
for line in f1:
# Replace & with correct escape
line = line.replace('&', '&')
if '{tempStartTime}' in line:
showLength = myShowDurations[showCounter]
print ("Show length: " + str(showLength))
currentTime = timeObject.strftime("%Y%m%d%H%M%S")
line = line.replace('{tempStartTime}', str(currentTime))
timeObject += timedelta(seconds=showLength)
currentTime = timeObject.strftime("%Y%m%d%H%M%S")
line = line.replace('{tempEndTime}', str(currentTime))
# Increase show counter
showCounter += 1
f2.write(line)
# Close xmltv
f1.close()
f2.close()
# Call the function
generateGuideData(temp_variables.tvDirectory, temp_variables.backup, list(temp_variables.showDurations))