Skip to content

Commit

Permalink
Add historical guide file cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-widrick committed May 4, 2021
1 parent f39aeb4 commit 80d5c2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions zap2it-GuideScrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#Additional Libraries for Parameter Parsing
import sys, getopt
#Libraries for historical copies
import datetime
import datetime, os

def sanitizeData(data):
#https://stackoverflow.com/questions/1091945/what-characters-do-i-need-to-escape-in-xml-documents
Expand Down Expand Up @@ -106,17 +106,15 @@ def buildXMLDate(inputDateString):
optConfigFile = arg
elif opt in ("-o","--ofile"):
optGuideFile = arg
print("Loading config: ", optConfigFile, " and outputting: ", optGuideFile)




print("Loading config: ", optConfigFile, " and outputting: ", optGuideFile)

#Configuration loading
Config = configparser.ConfigParser()
Config
Config.read(optConfigFile)


#Build authentication request
url = 'https://tvlistings.zap2it.com/api/user/login'
parameters = {
Expand Down Expand Up @@ -207,4 +205,11 @@ def buildXMLDate(inputDateString):
file.write(guideXML.encode('utf8'))
file.close()

#TODO Clean old files?
#Clean old files
outputFilePath = os.path.abspath(optGuideFile)
outputDir = os.path.dirname(outputFilePath)
for item in os.listdir(outputDir):
fileName = os.path.join(outputDir,item)
if os.path.isfile(fileName) & item.endswith('.xmltv') & (os.stat(fileName).st_mtime < time.time() - (int(Config.get("prefs","historicalGuideDays")) * 86400)):
os.remove(fileName)
sys.exit()
1 change: 1 addition & 0 deletions zap2itconfig.ini.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Password: examplePass
[prefs]
country: USA
zipCode: 55555
historicalGuideDays: 14

1 comment on commit 80d5c2a

@daniel-widrick
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rudimentary historical file clean up to address issues raised in #7

Please sign in to comment.