Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated for Kodi 19.0-ALPHA1 #4

Merged
merged 8 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/lib/b808common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#dummy file to make this a package
from b808common import *
from .b808common import *
27 changes: 13 additions & 14 deletions resources/lib/b808common/b808common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!
Expand Down Expand Up @@ -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())])


################################################################################
Expand Down Expand Up @@ -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)

##############################################################################
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -322,6 +324,3 @@ def getThumbnailModeID():
XBMC_VERSION = "P*"
if VERSION_NUMBER >= 22.9:
XBMC_VERSION = ">P"



39 changes: 28 additions & 11 deletions resources/lib/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -76,21 +76,42 @@ 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

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:
image.retrieve(FTPSTUB + 'IDE00035.background.png', imageFileRGB )
http = urllib3.PoolManager()
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)
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, headers=headers)
with open(imageFileRGB, 'wb') as out:
while True:
data = r.read(65536)
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)
Expand Down Expand Up @@ -230,7 +251,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()
Expand Down Expand Up @@ -277,7 +298,3 @@ def buildImages(radarCode, updateRadarBackgrounds, backgroundsPath, overlayLoopP
buildImages(radarCode, True, backgroundsPath, overlayLoopPath)
log(os.listdir(backgroundsPath))
log(os.listdir(overlayLoopPath))




14 changes: 7 additions & 7 deletions resources/lib/weatherzone.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import requests
import re
from bs4 import BeautifulSoup
from urlparse import urlparse
from urllib.parse import urlparse
import datetime

try:
Expand Down Expand Up @@ -649,7 +649,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:
Expand All @@ -663,18 +663,18 @@ def getWeatherData(urlPath, extendedFeatures=True, XBMC_VERSION=17.0):
try:
header = row.find("th")
if header is not None and header.text == "Wind Direction":
windDirectionData = row.find_all("td")
for i in range(0,len(windDirectionData),2):
windDirections9am.append(windDirectionData[i].text.replace("\n",""))
windDirections3pm.append(windDirectionData[i+1].text.replace("\n",""))

windDirectionData = row.find_all("td")
for i in xrange(0, len(windDirectionData), 2):
windDirections9am.append(windDirectionData[i].text.replace("\n", ""))
windDirections3pm.append(windDirectionData[i + 1].text.replace("\n", ""))
except Exception as inst:
log(str(inst))
windDirections9am.append("?")
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])
Expand Down