@@ -63,6 +63,8 @@ def mainRun(userdata):
6363 device = settingsDict [setting ]
6464 if setting == 'days' :
6565 days = settingsDict [setting ]
66+ if setting == 'redays' :
67+ redays = settingsDict [setting ]
6668 if setting == 'xdetails' :
6769 xdetails = settingsDict [setting ]
6870 if setting == 'xdesc' :
@@ -125,7 +127,7 @@ def tvhMatchGet():
125127 logging .exception ('Exception: tvhMatch - %s' , e .strerror )
126128 pass
127129
128- def deleteOldCache (gridtimeStart , showList ):
130+ def deleteOldCache (gridtimeStart ):
129131 logging .info ('Checking for old cache files...' )
130132 try :
131133 if os .path .exists (cacheDir ):
@@ -134,22 +136,32 @@ def deleteOldCache(gridtimeStart, showList):
134136 oldfile = entry .split ('.' )[0 ]
135137 if oldfile .isdigit ():
136138 fn = os .path .join (cacheDir , entry )
137- if (int (oldfile ) + 10800 ) < gridtimeStart :
139+ if (int (oldfile )) < ( gridtimeStart + ( int ( redays ) * 86400 )) :
138140 try :
139141 os .remove (fn )
140142 logging .info ('Deleting old cache: %s' , entry )
141143 except OSError , e :
142144 logging .warn ('Error Deleting: %s - %s.' % (e .filename , e .strerror ))
143- elif not oldfile .isdigit ():
145+ except Exception as e :
146+ logging .exception ('Exception: deleteOldCache - %s' , e .strerror )
147+
148+ def deleteOldShowCache (showList ):
149+ logging .info ('Checking for old show cache files...' )
150+ try :
151+ if os .path .exists (cacheDir ):
152+ entries = os .listdir (cacheDir )
153+ for entry in entries :
154+ oldfile = entry .split ('.' )[0 ]
155+ if not oldfile .isdigit ():
144156 fn = os .path .join (cacheDir , entry )
145157 if oldfile not in showList :
146158 try :
147159 os .remove (fn )
148- logging .info ('Deleting old cache: %s' , entry )
160+ logging .info ('Deleting old show cache: %s' , entry )
149161 except OSError , e :
150162 logging .warn ('Error Deleting: %s - %s.' % (e .filename , e .strerror ))
151163 except Exception as e :
152- logging .exception ('Exception: deleteOldCache - %s' , e .strerror )
164+ logging .exception ('Exception: deleteOldshowCache - %s' , e .strerror )
153165
154166 def convTime (t ):
155167 return time .strftime ("%Y%m%d%H%M%S" ,time .localtime (int (t )))
@@ -739,6 +751,7 @@ def makeDescsortList(optList):
739751 logging .info ('No channel list found - adding all stations!' )
740752 if tvhoff == 'true' and tvhmatch == 'true' :
741753 tvhMatchGet ()
754+ deleteOldCache (gridtimeStart )
742755 while count < dayHours :
743756 filename = str (gridtime ) + '.json.gz'
744757 fileDir = os .path .join (cacheDir , filename )
@@ -776,7 +789,7 @@ def makeDescsortList(optList):
776789 else :
777790 showList = []
778791 xmltv ()
779- deleteOldCache ( gridtimeStart , showList )
792+ deleteOldShowCache ( showList )
780793 timeRun = round ((time .time () - pythonStartTime ),2 )
781794 logging .info ('zap2epg completed in %s seconds. ' , timeRun )
782795 logging .info ('%s Stations and %s Episodes written to xmltv.xml file.' , str (stationCount ), str (episodeCount ))
0 commit comments