Skip to content

Commit ffa873b

Browse files
bossanova808bossanova808
andauthored
[weather.ozweather] 2.1.6 (#2768)
Co-authored-by: bossanova808 <[email protected]>
1 parent 9527f47 commit ffa873b

File tree

13 files changed

+354
-300
lines changed

13 files changed

+354
-300
lines changed

weather.ozweather/addon.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="weather.ozweather" name="Oz Weather" version="2.1.5" provider-name="Bossanova808">
2+
<addon id="weather.ozweather" name="Oz Weather" version="2.1.6" provider-name="Bossanova808">
33
<requires>
44
<import addon="xbmc.python" version="3.0.0"/>
55
<import addon="script.module.requests" version="2.22.0+matrix.1"/>
66
<import addon="script.module.beautifulsoup4" version="4.8.2+matrix.1"/>
77
<import addon="script.module.pytz" version="3.0+matrix.2"/>
8-
<import addon="script.module.bossanova808" version="1.0.0"/>
8+
<import addon="script.module.bossanova808" version="1.0.2"/>
99
</requires>
1010
<extension point="xbmc.python.weather" library="default.py"/>
1111
<extension point="xbmc.addon.metadata">
@@ -23,8 +23,9 @@
2323
<icon>icon.png</icon>
2424
<fanart>fanart.jpg</fanart>
2525
</assets>
26-
<news>v2.1.5 Minor fixes
27-
- Fix feels like calculation when data not returned by BOM, and Current.Wind
26+
<news>v2.1.6 Performance improvements, prep for Piers
27+
- Improve performance when used with multiple Kodi Profiles by using a shared cache (stored under special://temp/ozweather)
28+
- A bunch of code improvements and defensive programming to cope with scenarios where things are not at times available
2829
</news>
2930
</extension>
3031
</addon>

weather.ozweather/changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v2.1.6 Performance improvements, prep for Piers
2+
- Improve performance when used with multiple Kodi Profiles by using a shared cache (stored under special://temp/ozweather)
3+
- A bunch of code improvements and defensive programming to cope with scenarios where things are not at times available
4+
5+
16
v2.1.5 Minor fixes
27
- Fix feels like calculation when data not returned by BOM, and Current.Wind
38

weather.ozweather/resources/language/resource.language.en_gb/strings.po

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ msgstr ""
7474

7575
msgctxt "#32208"
7676
msgid "Enter postcode, suburb or area."
77-
msgstr "
77+
msgstr ""
7878

7979
msgctxt "#32209"
8080
msgid "Radar backgrounds not showing? Try forcing a refresh"
81-
msgstr "
81+
msgstr ""
8282

8383
msgctxt "#32210"
8484
msgid "Refresh all radar backgrounds on next weather fetch?"
85-
msgstr "
85+
msgstr ""
8686

8787
msgctxt "#32211"
8888
msgid "Closest Radar "
89-
msgstr "
89+
msgstr ""
9090

9191
msgctxt "#32212"
9292
msgid "If entered, these radar codes overrule the closest found."
93-
msgstr "
93+
msgstr ""

weather.ozweather/resources/lib/abc/abc_video.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
# -*- coding: utf-8 -*-
21
import requests
32
import sys
43
import xbmc
4+
import xbmcgui
5+
import json
56
from bs4 import BeautifulSoup
67

7-
# Allow for unit testing this file
8+
# Allow for unit testing this file (remember to install kodistubs!)
89
# This brings this addon's resources, and bossanova808 module stuff into scope
910
# (when running this module outside Kodi)
1011
if not xbmc.getUserAgent():
1112
sys.path.insert(0, '../../..')
1213
sys.path.insert(0, '../../../../script.module.bossanova808/resources/lib')
1314

1415
from resources.lib.store import Store
15-
from bossanova808.utilities import *
16+
from bossanova808.constants import CWD
17+
from bossanova808.logger import Logger
1618

1719

1820
def scrape_and_play_abc_weather_video():
@@ -21,8 +23,11 @@ def scrape_and_play_abc_weather_video():
2123
"""
2224
url = get_abc_weather_video_link()
2325
# Construct an offscreen list item with metadata...
26+
if not url:
27+
xbmcgui.Dialog().notification("OzWeather", "Couldn't retrieve ABC weather video - sorry!", xbmcgui.NOTIFICATION_ERROR, 4000)
28+
return
2429
item = xbmcgui.ListItem(path=url)
25-
item.setProperty('mimetype', 'video/mpeg')
30+
item.setProperty('mimetype', 'video/mp4')
2631
item.setInfo('Video', {'title': 'ABC Weather In 90 Seconds'})
2732
item.setArt({'thumb': f'{CWD}/resources/weather-in-90-seconds.png'})
2833
# ...and then play it, fullscreen
@@ -33,9 +38,13 @@ def scrape_and_play_abc_weather_video():
3338
# See bottom of this file for notes on matching the video links (& Store.py for the regex)
3439
def get_abc_weather_video_link():
3540
try:
36-
r = requests.get(Store.ABC_URL)
41+
r = requests.get(Store.ABC_URL, timeout=15)
3742
bs = BeautifulSoup(r.text, "html.parser")
3843
json_string = bs.find("script", {'type': 'application/json', "id": "__NEXT_DATA__"})
44+
if not json_string or not json_string.string:
45+
error_msg = "ABC __NEXT_DATA__ script not found on page, couldn't extract ABC weather video link"
46+
Logger.error(error_msg)
47+
raise ValueError(error_msg)
3948
json_object = json.loads(json_string.string)
4049
# Logger.debug(json_object)
4150
# Put the json blob into: https://jsonhero.io/j/JU0I9LB4AlLU
@@ -48,7 +57,7 @@ def get_abc_weather_video_link():
4857
return sorted(urls, key=lambda x: x['bitrate'], reverse=True)[0]['file']
4958

5059
except Exception as inst:
51-
Logger.error("Couldn't get ABC video URL from scraped page: " + str(inst))
60+
Logger.error(f"Couldn't get ABC video URL from scraped page: {inst}")
5261
return ""
5362

5463

weather.ozweather/resources/lib/bom/bom_forecast.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
import math
77
import xbmc
88

9-
# Allow for unit testing this file
9+
# Allow for unit testing this file e (remember to install kodistubs!)
1010
# This brings this addon's resources, and bossanova808 module stuff into scope
1111
# (when running this module outside Kodi)
1212
if not xbmc.getUserAgent():
1313
sys.path.insert(0, '../../..')
1414
sys.path.insert(0, '../../../../script.module.bossanova808/resources/lib')
1515

1616
from resources.lib.store import Store
17-
from bossanova808.utilities import *
1817
from bossanova808.logger import Logger
1918

2019
"""
@@ -48,11 +47,7 @@ def set_key(weather_data, index, key, value):
4847

4948
if index == 0:
5049
weather_data['Current.' + key] = value.strip()
51-
weather_data['Current.' + key] = value.strip()
52-
5350
weather_data['Day' + str(index) + '.' + key] = value.strip()
54-
weather_data['Day' + str(index) + '.' + key] = value.strip()
55-
weather_data['Daily.' + str(index + 1) + '.' + key] = value.strip()
5651
weather_data['Daily.' + str(index + 1) + '.' + key] = value.strip()
5752

5853

@@ -121,9 +116,9 @@ def bom_forecast(geohash):
121116

122117
bom_api_current_observations_url = f'{bom_api_url_areahash}/observations'
123118
bom_api_forecast_seven_days_url = f'{bom_api_url_areahash}/forecasts/daily'
124-
# FUTURE? - these API end points exist, but are not yet used by OzWeather
125-
# bom_api_forecast_three_hourly_url = f'{bom_api_url_areahash}/forecasts/3-hourly'
126-
# bom_api_forecast_rain = f'{bom_api_url_areahash}/forecast/rain'
119+
# FUTURE? - these API end points exist, but are not yet actually used by OzWeather
120+
# bom_api_forecast_three_hourly_url = f"{bom_api_url_areahash}/forecasts/3-hourly"
121+
# bom_api_forecast_rain = f"{bom_api_url_areahash}/forecast/rain"
127122

128123
# Holders for the BOM JSON API results...
129124
area_information = None
@@ -139,7 +134,7 @@ def bom_forecast(geohash):
139134
now = datetime.datetime.now()
140135

141136
try:
142-
r = requests.get(bom_api_area_information_url)
137+
r = requests.get(bom_api_area_information_url, timeout=15)
143138
area_information = r.json()["data"]
144139
Logger.debug(area_information)
145140
if area_information:
@@ -153,7 +148,7 @@ def bom_forecast(geohash):
153148

154149
# Get CURRENT OBSERVATIONS
155150
try:
156-
r = requests.get(bom_api_current_observations_url)
151+
r = requests.get(bom_api_current_observations_url, timeout=15)
157152
current_observations = r.json()["data"]
158153
weather_data['ObservationsUpdated'] = utc_str_to_local_str(r.json()["metadata"]["issue_time"], time_zone=location_timezone)
159154
weather_data['ObservationsStation'] = r.json()["data"]['station']['name']
@@ -173,7 +168,7 @@ def bom_forecast(geohash):
173168

174169
# Get 7-DAY FORECAST
175170
try:
176-
r = requests.get(bom_api_forecast_seven_days_url)
171+
r = requests.get(bom_api_forecast_seven_days_url, timeout=15)
177172
forecast_seven_days = r.json()["data"]
178173
weather_data['ForecastUpdated'] = utc_str_to_local_str(r.json()["metadata"]["issue_time"], time_zone=location_timezone)
179174
weather_data['ForecastRegion'] = r.json()["metadata"]["forecast_region"].title()
@@ -187,7 +182,7 @@ def bom_forecast(geohash):
187182
# FUTURE?
188183
# # Get 3 HOURLY FORECAST
189184
# try:
190-
# r = requests.get(bom_api_forecast_three_hourly_url)
185+
# r = requests.get(bom_api_forecast_three_hourly_url, timeout=15)
191186
# forecast_three_hourly = r.json()["data"]
192187
# log(forecast_three_hourly)
193188
#
@@ -197,7 +192,7 @@ def bom_forecast(geohash):
197192
#
198193
# # Get RAIN FORECAST
199194
# try:
200-
# r = requests.get(bom_api_forecast_rain)
195+
# r = requests.get(bom_api_forecast_rain, timeout=15)
201196
# forecast_rain = r.json()["data"]
202197
# log(forecast_rain)
203198
#
@@ -285,7 +280,7 @@ def bom_forecast(geohash):
285280

286281
weather_data['Current.WarningsText'] = warnings_text
287282

288-
# 7 DAY FORECAST
283+
# 7-DAY FORECAST
289284
if forecast_seven_days:
290285
weather_data['Current.Condition'] = forecast_seven_days[0]['short_text']
291286
weather_data['Current.ConditionLong'] = forecast_seven_days[0]['extended_text']

weather.ozweather/resources/lib/bom/bom_location.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import requests
22
import sys
33
import xbmc
4+
import xbmcgui
45

5-
# Allow for unit testing this file
6+
# Allow for unit testing this file (remember to install kodistubs!)
67
# This brings this addon's resources, and bossanova808 module stuff into scope
7-
# (when running this module outside Kodi)
8+
# (only when running this module *outside* of Kodi)
89
if not xbmc.getUserAgent():
910
sys.path.insert(0, '../../..')
1011
sys.path.insert(0, '../../../../script.module.bossanova808/resources/lib')
1112

12-
from resources.lib.bom.bom_radar import *
13-
from bossanova808.utilities import *
13+
from resources.lib.store import Store
14+
from resources.lib.bom.bom_radar import closest_radar_to_lat_lon
15+
from bossanova808.constants import ADDON, ADDON_NAME, TRANSLATE
1416
from bossanova808.logger import Logger
1517

1618

@@ -23,7 +25,7 @@ def get_bom_locations_for(text):
2325
location_geohashes = []
2426

2527
try:
26-
r = requests.get(Store.BOM_API_LOCATIONS_URL, params={'search': text})
28+
r = requests.get(Store.BOM_API_LOCATIONS_URL, params={'search': text}, timeout=15)
2729
for result in r.json()['data']:
2830
Logger.debug(result)
2931
locations.append(f'{result["name"]}, {result["state"]} {result["postcode"]} ({result["geohash"]})')
@@ -45,7 +47,7 @@ def find_bom_location():
4547
What we need is actually a geohash we can then use with the BOM API
4648
Save the chosen result, e.g. Ascot Vale, VIC 3032 and geohash r1r11df
4749
"""
48-
keyboard = xbmc.Keyboard('', LANGUAGE(32195), False)
50+
keyboard = xbmc.Keyboard('', TRANSLATE(32195), False)
4951
keyboard.doModal()
5052

5153
if keyboard.isConfirmed() and keyboard.getText() != '':
@@ -68,10 +70,10 @@ def find_bom_location():
6870
# Don't save the settings is this goes wrong
6971
location_info_url = f'https://api.weather.bom.gov.au/v1/locations/{location_geohashes[selected]}'
7072
try:
71-
location_info = requests.get(location_info_url).json()['data']
73+
location_info = requests.get(location_info_url, timeout=15).json()['data']
7274
Logger.debug(location_info)
7375
except:
74-
Logger.debug("Error retrieving location info for geohash {location_geohashes[selected]}")
76+
Logger.debug(f"Error retrieving location info for geohash {location_geohashes[selected]}")
7577
raise
7678

7779
# Save the geohash and latitude and longitude of the location

0 commit comments

Comments
 (0)