Skip to content

Commit

Permalink
Merge pull request #2463 from bossanova808/weather.ozweather@matrix
Browse files Browse the repository at this point in the history
[weather.ozweather@matrix] 2.0.8
  • Loading branch information
basrieter authored Jun 2, 2023
2 parents 76eae69 + 7b5c1b8 commit cb56d9e
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 107 deletions.
6 changes: 3 additions & 3 deletions weather.ozweather/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="weather.ozweather" name="Oz Weather" version="2.0.6" provider-name="Bossanova808">
<addon id="weather.ozweather" name="Oz Weather" version="2.0.8" provider-name="Bossanova808">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.requests" version="2.22.0+matrix.1"/>
Expand All @@ -22,8 +22,8 @@
<icon>icon.png</icon>
<fanart>fanart.jpg</fanart>
</assets>
<news>v2.0.6
- Update list of radars
<news>v2.0.8
- Fix for moved ABC weather videos, update list of radars
</news>
</extension>
</addon>
3 changes: 3 additions & 0 deletions weather.ozweather/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.0.8
- Fix for moved ABC weather videos, update list of radars

2.0.6
- Update list of radars

Expand Down
Binary file added weather.ozweather/resources/ABC.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 33 additions & 11 deletions weather.ozweather/resources/lib/abc/abc_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,33 @@
from resources.lib.common import *


def get_abc_weather_video_link(quality):
def scrape_and_play_abc_weather_video():
"""
On-demand scrape the current ABC video URL and then play it back, with appropriate metadata/art etc.
"""
url = get_abc_weather_video_link()
# Construct an offscreen list item with metadata...
item = xbmcgui.ListItem(path=url)
item.setProperty('mimetype', 'video/mpeg')
item.setInfo('Video', { 'title' : 'ABC Weather In 90 Seconds'})
item.setArt({'thumb': f'{CWD}/resources/ABC.png'})
# ...and then play it, fullscreen
xbmc.Player().play(url, item, False)
pass

# Seems like the best/trw option has been removed, so just map these to 1000k
if quality == "Best" or quality == "trw":
quality = "1000k"

# See bottom of this file for notes on matching the video links (& Store.py for the regex)
def get_abc_weather_video_link():

try:
r = requests.get(Store.ABC_URL)
video = re.findall(Store.ABC_WEATHER_VIDEO_PATTERN, r.text)
videos = re.findall(Store.ABC_WEATHER_VIDEO_PATTERN, r.text)

# for video in videos:
# log(video)

try:
url = f'{Store.ABC_STUB}{video[0][0]}/WIN{video[0][1]}_{quality}.mp4'
url = f'{Store.ABC_STUB}/{videos[1][0]}/{videos[1][1]}/{videos[1][2]}/{videos[1][3]}.mp4'
return url
except Exception as inst:
log("Couldn't get ABC video URL from scraped page: " + str(inst))
Expand All @@ -36,19 +52,25 @@ def get_abc_weather_video_link(quality):
# UNIT TESTING
if __name__ == "__main__":
log("\nTesting scraping of ABC Weather Video - here's the 'Best' link:\n")
log(get_abc_weather_video_link("Best") + "\n")
log(get_abc_weather_video_link())


# ABC VIDEO URL NOTES
# > 2023_05 - CURRENT ABC VIDEO URL NOTES
# view the source on: https://www.abc.net.au/news/weather
# search for 'mp4'
# Regex in Store.py used to match the URL format
# Multiple matches will be found - first is a definition/download link (.mpg)
# 2nd is the highest quality stream (720p) - the one we want.
# https://mediacore-live-production.akamaized.net/video/01/im/Z/0m.mp4

# < 2023_05 - LEGACY INFO
# note date and quality level variables...
# view source on https://www.abc.net.au/news/newschannel/weather-in-90-seconds/ and find mp4 to see this list,
# view source on https://www.abc.net.au/news/newschannel/weather-in-90-seconds/ and find mp4 to see this list,
# the end of the URL can change regularly

# {'url': 'https://abcmedia.akamaized.net/news/news24/wins/201403/WINs_Weather1_0703_1000k.mp4', 'contentType': 'video/mp4', 'codec': 'AVC', 'bitrate': '928', 'width': '1024', 'height': '576', 'filesize': '11657344'}
# {'url': 'https://abcmedia.akamaized.net/news/news24/wins/201403/WINs_Weather1_0703_256k.mp4', 'contentType': 'video/mp4', 'codec': 'AVC', 'bitrate': '170', 'width': '320', 'height': '180', 'filesize': '2472086'}
# {'url': 'https://abcmedia.akamaized.net/news/news24/wins/201403/WINs_Weather1_0703_512k.mp4', 'contentType': 'video/mp4', 'codec': 'AVC', 'bitrate': '400', 'width': '512', 'height': '288', 'filesize': '5328218'}
# {'url': 'https://abcmedia.akamaized.net/news/news24/wins/201403/WINs_Weather1_0703_trw.mp4', 'contentType': 'video/mp4', 'codec': 'AVC', 'bitrate': '1780', 'width': '1280', 'height': '720', 'filesize': '21599356'}
# Other URLs - should match any of these
# https://abcmedia.akamaized.net/news/news24/wins/201409/WINm_Update1_0909_VSB03WF2_512k.mp4&
# https://abcmedia.akamaized.net/news/news24/wins/201409/WINs_Weather2_0209_trw.mp4

49 changes: 26 additions & 23 deletions weather.ozweather/resources/lib/bom/bom_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"""


# This is a hack fix for a wicked long standing Python bug...
# This is a hack fix for a wicked long-standing Python bug...
# See: https://forum.kodi.tv/showthread.php?tid=112916
# noinspection PyMethodOverriding,PyShadowingBuiltins,SpellCheckingInspection
class ProxyDatetime(datetime.datetime):
@staticmethod
def strptime(date_string, format):
Expand All @@ -30,6 +31,7 @@ def strptime(date_string, format):
datetime.datetime = ProxyDatetime


# noinspection PyShadowingNames
def set_key(weather_data, index, key, value):
"""
Set a key - for old and new weather label support
Expand All @@ -50,6 +52,7 @@ def set_key(weather_data, index, key, value):
weather_data['Daily.' + str(index + 1) + '.' + key] = value.strip()


# noinspection PyShadowingNames
def set_keys(weather_data, index, keys, value):
"""
Set a group of keys at once - for old and new weather label support
Expand Down Expand Up @@ -91,6 +94,7 @@ def utc_str_to_local_str(utc_str: str, utc_format: str = '%Y-%m-%dT%H:%M:%SZ', l
return local_time.strftime(local_format).lstrip('0').lower()


# noinspection PyBroadException,PyShadowingNames
def bom_forecast(geohash):
"""
Return are information, current observations, warnings, and forecast for the given geohash
Expand All @@ -102,8 +106,6 @@ def bom_forecast(geohash):
# Gather the weather data into a dict from which we will later set all the Kodi labels
weather_data = {}



# The areahash is the geohash minus the last character
areahash = geohash[:-1]

Expand All @@ -116,18 +118,18 @@ def bom_forecast(geohash):
bom_api_current_observations_url = f'{bom_api_url_areahash}/observations'
bom_api_forecast_seven_days_url = f'{bom_api_url_areahash}/forecasts/daily'
# FUTURE? - these API end points exist, but are not yet used by OzWeather
bom_api_forecast_three_hourly_url = f'{bom_api_url_areahash}/forecasts/3-hourly'
bom_api_forecast_rain = f'{bom_api_url_areahash}/forecast/rain'
# bom_api_forecast_three_hourly_url = f'{bom_api_url_areahash}/forecasts/3-hourly'
# bom_api_forecast_rain = f'{bom_api_url_areahash}/forecast/rain'

# Holders for the BOM JSON API results...
area_information = None
current_observations = None
# current_observations = None
warnings = None
forecast_seven_days = None
# forecast_seven_days = None
# forecast_three_hourly = None
# forecast_rain = None

# Get the AREA INFORMATION, including the location's timezone so we can correctly show the location local times
# Get the AREA INFORMATION, including the location's timezone, so we can correctly show the location local times
location_timezone = ""
# In case we can't get the localised now time, below...
now = datetime.datetime.now()
Expand All @@ -143,7 +145,7 @@ def bom_forecast(geohash):
# For any date comparisons - this is the localised now...
now = datetime.datetime.now(location_timezone)

except Exception as inst:
except:
log(f'Error retrieving area information from {bom_api_area_information_url}')

# Get CURRENT OBSERVATIONS
Expand All @@ -154,7 +156,7 @@ def bom_forecast(geohash):
weather_data['ObservationsStation'] = r.json()["data"]['station']['name']
log(current_observations)

except Exception as inst:
except:
log(f'Error retrieving current observations from {bom_api_current_observations_url}')
return False

Expand All @@ -164,10 +166,10 @@ def bom_forecast(geohash):
warnings = r.json()["data"]
log(warnings)

except Exception as inst:
except:
log(f'Error retrieving warnings from {bom_api_warnings_url}')

# Get 7 DAY FORECAST
# Get 7-DAY FORECAST
try:
r = requests.get(bom_api_forecast_seven_days_url)
forecast_seven_days = r.json()["data"]
Expand All @@ -176,7 +178,7 @@ def bom_forecast(geohash):
weather_data['ForecastType'] = r.json()["metadata"]["forecast_type"].title()
log(forecast_seven_days)

except Exception as inst:
except:
log(f'Error retrieving seven day forecast from {bom_api_forecast_seven_days_url}')
return False

Expand All @@ -203,11 +205,11 @@ def bom_forecast(geohash):

# CURRENT OBSERVATIONS

# IMPORTANT - to avoid issues with Kodi malforming weather values due to 'magic'
# (the magic is presumably because Kodi seeks to support both farenheit and celsius, so unofrtunately tends to return 0
# for any non-numeric value in these labels...
# IMPORTANT - to avoid issues with Kodi mal-forming weather values due to 'magic'
# (the magic is presumably because Kodi seeks to support both Fahrenheit and Celsius, so unfortunately tends to return 0
# for any non-numeric value in these labels...)
# ...So, we set the normal Kodi weather labels as best we can.
# ...But, we also set a version with OzW_ prepended to the label name, which is used in OzWeather Skin files to avoid this.
# ...But, we also set a version with OzW_ prepended to the label name, which is used in OzWeather Skin files, to avoid this.

if current_observations:
weather_data['Current.Temperature'] = current_observations['temp']
Expand Down Expand Up @@ -247,7 +249,7 @@ def bom_forecast(geohash):
warnings_text = ""
if warnings:
for i, warning in enumerate(warnings):
# Warnings body...only major warnings as we don't need every little message about sheep grazing etc..
# Warnings body...only major warnings as we don't need every little message about sheep grazing etc...
if warning['warning_group_type'] == 'major':
# Don't really care when it was issue, if it hasn't expired, it's current, so show it..
# warning_issued = utc_str_to_local_str(warning['issue_time'], local_format='%d/%m %I:%M%p', time_zone=location_timezone)
Expand Down Expand Up @@ -311,6 +313,7 @@ def bom_forecast(geohash):
# However, preferentially try and use the short text, to cope with BOM madness like:
# "icon_descriptor":"mostly_sunny","short_text":"Mostly cloudy."
icon_descriptor = forecast_seven_days[i]['icon_descriptor']
descriptor_from_short_text = None
if forecast_seven_days[i]['short_text']:
descriptor_from_short_text = forecast_seven_days[i]['short_text'].lower()
descriptor_from_short_text = descriptor_from_short_text.replace(' ', '_').replace('.', '').strip()
Expand Down Expand Up @@ -393,7 +396,7 @@ def bom_forecast(geohash):

# TESTING for skin scrolling - DON'T LEAVE THIS UNCOMMENTED!
# for j in range(0, 5):
# extended_text += "add some more random text on the end so it just goes on and on\n"
# extended_text += "add some more random text on the end, so it just goes on and on\n"

set_key(weather_data, i, "OutlookLong", extended_text)
set_key(weather_data, i, "ConditionLong", extended_text)
Expand All @@ -415,12 +418,12 @@ def bom_forecast(geohash):
geohashes_to_test = ['r1r11df', 'r1f94ew']
for geohash in geohashes_to_test:
log(f'Getting weather data from BOM for geohash "{geohash}"')
weather_data = bom_forecast(geohash)
test_data = bom_forecast(geohash)

for key in sorted(weather_data):
if weather_data[key] == "?" or weather_data[key] == "na":
for key in sorted(test_data):
if test_data[key] == "?" or test_data[key] == "na":
log("**** MISSING: ")
log(f'{key}: "{weather_data[key]}"')
log(f'{key}: "{test_data[key]}"')

"""
BOM API
Expand Down
4 changes: 1 addition & 3 deletions weather.ozweather/resources/lib/bom/bom_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
if not xbmc.getUserAgent():
sys.path.insert(0, '../../..')

from resources.lib.store import Store
from resources.lib.common import *
from resources.lib.bom.bom_radar import *


Expand All @@ -31,7 +29,7 @@ def get_bom_locations_for(text):
return locations, location_geohashes

except Exception as inst:
log(f'Exception getting locations from {bom_locations_api} for search term {text}')
log(f'Exception getting locations from {Store.BOM_API_LOCATIONS_URL} for search term {text}')
log(str(inst))
raise

Expand Down
Loading

0 comments on commit cb56d9e

Please sign in to comment.