1414# along with this program. If not, see <http://www.gnu.org/licenses/>.
1515################################################################################
1616
17- import urllib2
17+ import urllib . request , urllib . error , urllib . parse
1818import base64
1919import codecs
2020import time
@@ -110,11 +110,11 @@ def tvhMatchGet():
110110 channels_url = tvhUrlBase + '/api/channel/grid?all=1&limit=999999999&sort=name&filter=[{"type":"boolean","value":true,"field":"enabled"}]'
111111 if usern is not None and passw is not None :
112112 logging .info ('Adding Tvheadend username and password to request url...' )
113- request = urllib2 .Request (channels_url )
113+ request = urllib . request .Request (channels_url )
114114 request .add_header ('Authorization' , b'Basic ' + base64 .b64encode (usern + b':' + passw ))
115- response = urllib2 .urlopen (request )
115+ response = urllib . request .urlopen (request )
116116 else :
117- response = urllib2 .urlopen (channels_url )
117+ response = urllib . request .urlopen (channels_url )
118118 try :
119119 logging .info ('Accessing Tvheadend channel list from: %s' , tvhUrlBase )
120120 channels = json .load (response )
@@ -123,7 +123,7 @@ def tvhMatchGet():
123123 channelNum = ch ['number' ]
124124 tvhMatchDict [channelNum ] = channelName
125125 logging .info ('%s Tvheadend channels found...' , str (len (tvhMatchDict )))
126- except urllib2 .HTTPError as e :
126+ except urllib . error .HTTPError as e :
127127 logging .exception ('Exception: tvhMatch - %s' , e .strerror )
128128 pass
129129
@@ -140,7 +140,7 @@ def deleteOldCache(gridtimeStart):
140140 try :
141141 os .remove (fn )
142142 logging .info ('Deleting old cache: %s' , entry )
143- except OSError , e :
143+ except OSError as e :
144144 logging .warn ('Error Deleting: %s - %s.' % (e .filename , e .strerror ))
145145 except Exception as e :
146146 logging .exception ('Exception: deleteOldCache - %s' , e .strerror )
@@ -158,7 +158,7 @@ def deleteOldShowCache(showList):
158158 try :
159159 os .remove (fn )
160160 logging .info ('Deleting old show cache: %s' , entry )
161- except OSError , e :
161+ except OSError as e :
162162 logging .warn ('Error Deleting: %s - %s.' % (e .filename , e .strerror ))
163163 except Exception as e :
164164 logging .exception ('Exception: deleteOldshowCache - %s' , e .strerror )
@@ -267,9 +267,9 @@ def printStations(fh):
267267 try :
268268 logging .info ('Writing Stations to xmltv.xml file...' )
269269 try :
270- scheduleSort = OrderedDict (sorted (schedule .iteritems ( ), key = lambda x : int (x [1 ]['chnum' ])))
270+ scheduleSort = OrderedDict (sorted (iter ( schedule .items () ), key = lambda x : int (x [1 ]['chnum' ])))
271271 except :
272- scheduleSort = OrderedDict (sorted (schedule .iteritems ( ), key = lambda x : x [1 ]['chfcc' ]))
272+ scheduleSort = OrderedDict (sorted (iter ( schedule .items () ), key = lambda x : x [1 ]['chfcc' ]))
273273 for station in scheduleSort :
274274 fh .write ('\t <channel id=\" ' + station + '.zap2epg\" >\n ' )
275275 if 'chtvh' in scheduleSort [station ] and scheduleSort [station ]['chtvh' ] is not None :
@@ -533,8 +533,8 @@ def parseXdetails():
533533 url = 'https://tvlistings.zap2it.com/api/program/overviewDetails'
534534 data = 'programSeriesID=' + EPseries
535535 try :
536- URLcontent = urllib2 .Request (url , data = data )
537- JSONcontent = urllib2 .urlopen (URLcontent ).read ()
536+ URLcontent = urllib . request .Request (url , data = data )
537+ JSONcontent = urllib . request .urlopen (URLcontent ).read ()
538538 if JSONcontent :
539539 with open (fileDir ,"wb+" ) as f :
540540 f .write (JSONcontent )
@@ -544,7 +544,7 @@ def parseXdetails():
544544 time .sleep (1 )
545545 retry -= 1
546546 logging .warn ('Retry downloading missing details data for: %s' , EPseries )
547- except urllib2 . URLError , e :
547+ except urllib . error . URLError as e :
548548 time .sleep (1 )
549549 retry -= 1
550550 logging .warn ('Retry downloading details data for: %s - %s' , EPseries , e )
@@ -583,7 +583,7 @@ def parseXdetails():
583583 os .remove (fileDir )
584584 logging .info ('Deleting %s due to TBA listings' , filename )
585585 showList .remove (edict ['epseries' ])
586- except OSError , e :
586+ except OSError as e :
587587 logging .warn ('Error Deleting: %s - %s.' % (e .filename , e .strerror ))
588588 except Exception as e :
589589 logging .exception ('Could not parse TBAcheck for: %s - %s' , episode , e )
@@ -616,14 +616,14 @@ def addXDetails(edict):
616616 prog = ""
617617 plot = ""
618618 descsort = ""
619- bullet = u "\u2022 "
620- hyphen = u "\u2013 "
619+ bullet = "\u2022 "
620+ hyphen = "\u2013 "
621621 newLine = "\n "
622622 space = " "
623- colon = u "\u003A "
624- vbar = u "\u007C "
625- slash = u "\u2215 "
626- comma = u "\u002C "
623+ colon = "\u003A "
624+ vbar = "\u007C "
625+ slash = "\u2215 "
626+ comma = "\u002C "
627627
628628 def getSortName (opt ):
629629 return {
@@ -759,7 +759,7 @@ def makeDescsortList(optList):
759759 try :
760760 logging .info ('Downloading guide data for: %s' , str (gridtime ))
761761 url = 'http://tvlistings.zap2it.com/api/grid?lineupId=×pan=3&headendId=' + lineupcode + '&country=' + country + '&device=' + device + '&postalCode=' + zipcode + '&time=' + str (gridtime ) + '&pref=-&userId=-'
762- saveContent = urllib2 .urlopen (url ).read ()
762+ saveContent = urllib . request .urlopen (url ).read ()
763763 savepage (fileDir , saveContent )
764764 except :
765765 logging .warn ('Could not download guide data for: %s' , str (gridtime ))
@@ -777,7 +777,7 @@ def makeDescsortList(optList):
777777 try :
778778 os .remove (fileDir )
779779 logging .info ('Deleting %s due to TBA listings' , filename )
780- except OSError , e :
780+ except OSError as e :
781781 logging .warn ('Error Deleting: %s - %s.' % (e .filename , e .strerror ))
782782 except :
783783 logging .warn ('JSON file error for: %s - deleting file' , filename )
0 commit comments