From af97ba9a4674c80222be3481167bdd16b11b78e4 Mon Sep 17 00:00:00 2001 From: heitbaum <6086324+heitbaum@users.noreply.github.com> Date: Sat, 4 Jan 2020 20:27:59 +1100 Subject: [PATCH 1/7] Update bom.py --- resources/lib/bom.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/resources/lib/bom.py b/resources/lib/bom.py index 094a1ef..7bfe9b1 100644 --- a/resources/lib/bom.py +++ b/resources/lib/bom.py @@ -21,7 +21,7 @@ import os, sys, shutil import time import ftplib -import urllib, urllib2 +import urllib.request, urllib.parse, urllib.error, urllib3 try: from xbmc import log as log @@ -41,7 +41,7 @@ def log(str): def downloadBackground(radarCode, fileName, backgroundsPath): # Needed due to bug in python 2.7 urllib - https://stackoverflow.com/questions/44733710/downloading-second-file-from-ftp-fails - urllib.urlcleanup() + urllib.request.urlcleanup() outFileName = fileName @@ -76,21 +76,39 @@ def downloadBackground(radarCode, fileName, backgroundsPath): log("Downloading missing background image....[%s] as [%s]" % (fileName, outFileName)) #ok get ready to retrieve some images - image = urllib.URLopener() + #image = urllib.request.URLopener() imageFileIndexed = backgroundsPath + "idx." + fileName imageFileRGB = backgroundsPath + outFileName #special case for national radar background (already an RGB image) if "background.png" in fileName and '00004' in fileName: - image.retrieve(FTPSTUB + 'IDE00035.background.png', imageFileRGB ) + http = urllib3.PoolManager() + r = http.request('GET', HTTPSTUB + 'IDE00035.background.png', preload_content=False) + with open(imageFileRGB, 'wb') as out: + while True: + data = r.read(65536) + if not data: + break + out.write(data) + r.release_conn() + #image.retrieve(HTTPSTUB + 'IDE00035.background.png', imageFileRGB ) log("Got IDE00035.background.png as " + outFileName) #all other images...need to be converted from indexed colour to RGB else: try: #log(FTPSTUB + fileName) - image.retrieve(FTPSTUB + fileName, imageFileIndexed ) + #image.retrieve(HTTPSTUB + fileName, imageFileIndexed ) + http = urllib3.PoolManager() + r = http.request('GET', HTTPSTUB + fileName, preload_content=False) + with open(imageFileRGB, 'wb') as out: + while True: + data = r.read(chunk_size) + if not data: + break + out.write(data) + r.release_conn() except Exception as inst: - log("ftp failed with error: " + str(inst)) + log("http failed with error: " + str(inst)) try: log("Downloaded background texture...now converting from indexed file [" + imageFileIndexed + "] to RGB: " + fileName) @@ -230,7 +248,7 @@ def buildImages(radarCode, updateRadarBackgrounds, backgroundsPath, overlayLoopP log("Retrieving new radar image: " + imageToRetrieve) log("Output to file: " + outputFile) try: - radarImage = urllib2.urlopen(imageToRetrieve) + radarImage = urllib.request.urlopen(imageToRetrieve) fh = open( overlayLoopPath + "/" + outputFile , "wb") fh.write(radarImage.read()) fh.close() @@ -277,7 +295,3 @@ def buildImages(radarCode, updateRadarBackgrounds, backgroundsPath, overlayLoopP buildImages(radarCode, True, backgroundsPath, overlayLoopPath) log(os.listdir(backgroundsPath)) log(os.listdir(overlayLoopPath)) - - - - \ No newline at end of file From 952f00452d1e599afb7250db44d8f6e8068d1632 Mon Sep 17 00:00:00 2001 From: heitbaum <6086324+heitbaum@users.noreply.github.com> Date: Sat, 4 Jan 2020 20:29:04 +1100 Subject: [PATCH 2/7] Update weatherzone.py --- resources/lib/weatherzone.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/lib/weatherzone.py b/resources/lib/weatherzone.py index 66dd36d..fd87176 100644 --- a/resources/lib/weatherzone.py +++ b/resources/lib/weatherzone.py @@ -18,7 +18,7 @@ import requests from bs4 import BeautifulSoup -from urlparse import urlparse +from urllib.parse import urlparse import datetime try: @@ -637,7 +637,7 @@ def getWeatherData(urlPath, extendedFeatures = True, XBMC_VERSION=17.0): if header is not None and header.text == "Wind Speed": windSpeedData = row.find_all("td") - for i in xrange(0,len(windSpeedData),2): + for i in range(0,len(windSpeedData),2): windSpeeds9am.append(windSpeedData[i].text) windSpeeds3pm.append(windSpeedData[i+1].text) except Exception as inst: @@ -654,7 +654,7 @@ def getWeatherData(urlPath, extendedFeatures = True, XBMC_VERSION=17.0): if header is not None and header.text == "Wind Direction": windDirectionData = row.find_all("td") - for i in xrange(0,len(windDirectionData),2): + for i in range(0,len(windDirectionData),2): windDirections9am.append(windDirectionData[i].text.replace("\n","")) windDirections3pm.append(windDirectionData[i+1].text.replace("\n","")) except Exception as inst: @@ -663,7 +663,7 @@ def getWeatherData(urlPath, extendedFeatures = True, XBMC_VERSION=17.0): windDirections3pm.append("?") # Now join the stored wind data and set it... - for i in xrange(0,len(windSpeeds9am)): + for i in range(0,len(windSpeeds9am)): # setKey(i, "WindSpeed", "9am - " + windSpeeds9am[i] + ", 3pm - " + windSpeeds3pm[i]) setKey(i, "WindSpeed", windSpeeds3pm[i]) # setKey(i, "WindDirection", "9am - " + windDirections9am[i] + ", 3pm - " + windDirections3pm[i]) From e23361513ce9741971ae670177946d51e4e780b9 Mon Sep 17 00:00:00 2001 From: heitbaum <6086324+heitbaum@users.noreply.github.com> Date: Sat, 4 Jan 2020 20:29:39 +1100 Subject: [PATCH 3/7] Update __init__.py --- resources/lib/b808common/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/b808common/__init__.py b/resources/lib/b808common/__init__.py index 6dd44b0..bb23fea 100644 --- a/resources/lib/b808common/__init__.py +++ b/resources/lib/b808common/__init__.py @@ -1,2 +1,2 @@ #dummy file to make this a package -from b808common import * +from .b808common import * From 7213c15951729ee77ffc7058ca0b0efe3c270f97 Mon Sep 17 00:00:00 2001 From: heitbaum <6086324+heitbaum@users.noreply.github.com> Date: Sat, 4 Jan 2020 20:30:36 +1100 Subject: [PATCH 4/7] Update b808common.py --- resources/lib/b808common/b808common.py | 27 +++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/resources/lib/b808common/b808common.py b/resources/lib/b808common/b808common.py index 78af863..f6776bd 100644 --- a/resources/lib/b808common/b808common.py +++ b/resources/lib/b808common/b808common.py @@ -11,7 +11,7 @@ import xbmcplugin import xbmcvfs import xbmcgui -import urllib +import urllib.request, urllib.parse, urllib.error import sys import os import platform @@ -32,15 +32,17 @@ def log(message, inst=None, level=xbmc.LOGDEBUG): if isinstance (message,str): - message = message.decode("utf-8") - message = u'### %s - %s ### %s' % (ADDONNAME,VERSION, message) + #message = message.decode("utf-8") + message = '### %s - %s ### %s' % (ADDONNAME,VERSION, message) else: - message = u'### %s - %s ### %s' % (ADDONNAME,VERSION, message) + message = '### %s - %s ### %s' % (ADDONNAME,VERSION, message) if inst is None: - xbmc.log(message.encode("utf-8"), level ) + #xbmc.log(message.encode("utf-8"), level ) + xbmc.log(message, level ) else: - xbmc.log(message.encode("utf-8"), level ) + #xbmc.log(message.encode("utf-8"), level ) + xbmc.log(message, level ) xbmc.log("### " + ADDONNAME + "-" + VERSION + " ### Exception:" + format_exc(inst), level ) #log something even if debug logging is off - for important stuff only! @@ -106,7 +108,7 @@ def frontPadTo9Chars(shortStr): # Reverse the key value pairs in a dict def swap_dictionary(original_dict): - return dict([(v, k) for (k, v) in original_dict.iteritems()]) + return dict([(v, k) for (k, v) in list(original_dict.items())]) ################################################################################ @@ -143,17 +145,17 @@ def unquoteUni(text): #return urllib.unquote(text) _hexdig = '0123456789ABCDEFabcdef' _hextochr = dict((a+b, chr(int(a+b,16))) for a in _hexdig for b in _hexdig) - if isinstance(text, unicode): + if isinstance(text, str): text = text.encode('utf-8') res = text.split('%') - for i in xrange(1, len(res)): + for i in range(1, len(res)): item = res[i] try: res[i] = _hextochr[item[:2]] + item[2:] except KeyError: res[i] = '%' + item except UnicodeDecodeError: - res[i] = unichr(int(item[:2], 16)) + item[2:] + res[i] = chr(int(item[:2], 16)) + item[2:] return "".join(res) ############################################################################## @@ -183,7 +185,7 @@ def getParams(): # Build a plugin URL with urlencoded parameters def buildPluginURL(params): - return PLUGINSTUB + urllib.urlencode(params) + return PLUGINSTUB + urllib.parse.urlencode(params) ################################################################################ # Strip given chararacters from all members of a given list @@ -322,6 +324,3 @@ def getThumbnailModeID(): XBMC_VERSION = "P*" if VERSION_NUMBER >= 22.9: XBMC_VERSION = ">P" - - - From cf12ac06bdb5e8e793362c284f1027b99ad5cb45 Mon Sep 17 00:00:00 2001 From: heitbaum <6086324+heitbaum@users.noreply.github.com> Date: Sat, 4 Jan 2020 20:53:19 +1100 Subject: [PATCH 5/7] Update bom.py --- resources/lib/bom.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/resources/lib/bom.py b/resources/lib/bom.py index 7bfe9b1..8ff339d 100644 --- a/resources/lib/bom.py +++ b/resources/lib/bom.py @@ -98,15 +98,15 @@ def downloadBackground(radarCode, fileName, backgroundsPath): try: #log(FTPSTUB + fileName) #image.retrieve(HTTPSTUB + fileName, imageFileIndexed ) - http = urllib3.PoolManager() - r = http.request('GET', HTTPSTUB + fileName, preload_content=False) - with open(imageFileRGB, 'wb') as out: - while True: - data = r.read(chunk_size) - if not data: - break - out.write(data) - r.release_conn() + http = urllib3.PoolManager() + r = http.request('GET', HTTPSTUB + fileName, preload_content=False) + with open(imageFileRGB, 'wb') as out: + while True: + data = r.read(chunk_size) + if not data: + break + out.write(data) + r.release_conn() except Exception as inst: log("http failed with error: " + str(inst)) @@ -248,7 +248,7 @@ def buildImages(radarCode, updateRadarBackgrounds, backgroundsPath, overlayLoopP log("Retrieving new radar image: " + imageToRetrieve) log("Output to file: " + outputFile) try: - radarImage = urllib.request.urlopen(imageToRetrieve) + radarImage = urllib.request.urlopen(imageToRetrieve) fh = open( overlayLoopPath + "/" + outputFile , "wb") fh.write(radarImage.read()) fh.close() From 8fb93179fd6b177232f8f9855f328abf0de82210 Mon Sep 17 00:00:00 2001 From: heitbaum <6086324+heitbaum@users.noreply.github.com> Date: Sat, 4 Jan 2020 20:56:04 +1100 Subject: [PATCH 6/7] Update bom.py --- resources/lib/bom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/bom.py b/resources/lib/bom.py index 8ff339d..b6038bf 100644 --- a/resources/lib/bom.py +++ b/resources/lib/bom.py @@ -102,7 +102,7 @@ def downloadBackground(radarCode, fileName, backgroundsPath): r = http.request('GET', HTTPSTUB + fileName, preload_content=False) with open(imageFileRGB, 'wb') as out: while True: - data = r.read(chunk_size) + data = r.read(65536) if not data: break out.write(data) From 6a5edbefc4c4c193256d5db87df3b7fe323dc4d1 Mon Sep 17 00:00:00 2001 From: heitbaum <6086324+heitbaum@users.noreply.github.com> Date: Sat, 4 Jan 2020 22:17:37 +1100 Subject: [PATCH 7/7] Update bom.py updated code to have USERAGENT specified --- resources/lib/bom.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/resources/lib/bom.py b/resources/lib/bom.py index b6038bf..1d5a94e 100644 --- a/resources/lib/bom.py +++ b/resources/lib/bom.py @@ -80,10 +80,13 @@ def downloadBackground(radarCode, fileName, backgroundsPath): imageFileIndexed = backgroundsPath + "idx." + fileName imageFileRGB = backgroundsPath + outFileName + USERAGENT = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.1) Gecko/2008070208 Firefox/3.6" + headers = urllib3.util.request.make_headers(accept_encoding='gzip, deflate', keep_alive=True, user_agent=USERAGENT) + #special case for national radar background (already an RGB image) if "background.png" in fileName and '00004' in fileName: http = urllib3.PoolManager() - r = http.request('GET', HTTPSTUB + 'IDE00035.background.png', preload_content=False) + r = http.request('GET', HTTPSTUB + 'IDE00035.background.png', preload_content=False, headers=headers) with open(imageFileRGB, 'wb') as out: while True: data = r.read(65536) @@ -99,7 +102,7 @@ def downloadBackground(radarCode, fileName, backgroundsPath): #log(FTPSTUB + fileName) #image.retrieve(HTTPSTUB + fileName, imageFileIndexed ) http = urllib3.PoolManager() - r = http.request('GET', HTTPSTUB + fileName, preload_content=False) + r = http.request('GET', HTTPSTUB + fileName, preload_content=False, headers=headers) with open(imageFileRGB, 'wb') as out: while True: data = r.read(65536)