Skip to content

Commit

Permalink
Used locale date format for all dates.
Browse files Browse the repository at this point in the history
  • Loading branch information
wichmann committed Jan 19, 2024
1 parent 117da40 commit 59f255d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,5 @@ pyrightconfig.json
.ionide

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,python

docs/
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# TODO

* Löschen von Stationen in den Einstellungen
*
19 changes: 14 additions & 5 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
MAXDAYS = 10
SHELVE_FILE = xbmcvfs.translatePath(os.path.join(ADDON.getAddonInfo('profile'), 'weather.data'))

TEMP_UNIT = xbmc.getRegion('tempunit')
SPEED_UNIT = xbmc.getRegion('speedunit')
DATE_SHORT_FORMAT = xbmc.getRegion('dateshort')
DATE_LONG_FORMAT = xbmc.getRegion('datelong')
TIME_FORMAT = xbmc.getRegion('time')


def set_property(name, value):
"""Set a property on the weather window object."""
Expand Down Expand Up @@ -93,9 +99,11 @@ def set_properties_for_weather_data(weather_data):
current_data['surfacePressure'][current_hour]))
set_property('Current.Precipitation',
current_data['precipitationTotal'][current_hour])
sunrise = calc_time(weather_data['days'][0]['sunrise'])
sunrise = calc_time(
weather_data['days'][0]['sunrise'], f'{DATE_SHORT_FORMAT} {TIME_FORMAT}')
set_property('Today.Sunrise', sunrise)
sunset = calc_time(weather_data['days'][0]['sunset'])
sunset = calc_time(
weather_data['days'][0]['sunset'], f'{DATE_SHORT_FORMAT} {TIME_FORMAT}')
set_property('Today.Sunset', sunset)
set_property('Today.HighTemp', weather_data['days'][0]['temperatureMax'])
set_property('Today.LowTemp', weather_data['days'][0]['temperatureMin'])
Expand All @@ -114,16 +122,16 @@ def set_properties_for_weather_data(weather_data):
current_data['temperature'][current_hour]), div10(weather_data['days'][0]['windSpeed'])))
# fill in the forecast for the next days
for no, day in enumerate(weather_data['days']):
dt = datetime.fromisoformat(day['dayDate'])
# Day0.xxx - Day6.xxx
set_property(f'Day{no}.Title', day['dayDate'])
set_property(f'Day{no}.Title', dt.strftime(DATE_SHORT_FORMAT))
set_property(f'Day{no}.HighTemp', div10(day['temperatureMax']))
set_property(f'Day{no}.LowTemp', div10(day['temperatureMin']))
set_property(f'Day{no}.Outlook', DWD_ICON_MAPPING[day['icon']])
set_property(f'Day{no}.OutlookIcon',
get_icon_path_for_weather(day['icon']))
set_property(f'Day{no}.FanartCode', 'na')
# Daily.1.xxx - Daily.10.xxx
dt = datetime.fromisoformat(day['dayDate'])
set_property(f'Daily.{no}.LongDay', dt.strftime('%A'))
set_property(f'Daily.{no}.ShortDay', dt.strftime('%a'))
set_property(f'Daily.{no}.LongDate', dt.strftime('%d. %B'))
Expand Down Expand Up @@ -278,7 +286,8 @@ def main():
set_property('Current.Location', current_station_name)
set_property('Forecast.City', current_station_name)
set_property('Forecast.Country', 'Germany')
lat, lon = get_coordinates_for_station(current_station_name)
lat, lon = get_coordinates_for_station(
current_station_name)
set_property('Forecast.Latitude', lat)
set_property('Forecast.Longitude', lon)
set_property('Locations', len(get_station_names()))
Expand Down
6 changes: 2 additions & 4 deletions resources/lib/dwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,14 @@ def get_coordinates_for_station(station_name):
return (lat, lon)


def calc_time(timestamp):
def calc_time(timestamp, datetimeformat):
"""
Format the timestamp from DWD in the valid format for Kodi.
"""
try:
timestamp = int(timestamp) / 1000
dt = datetime.fromtimestamp(timestamp)
# TODO: Check whether the date format is correct.
# iso_fmt = '%Y-%m-%dT%H:%M:%S%z'
return str(dt)
return dt.strftime(datetimeformat)
except ValueError:
return ''

Expand Down

0 comments on commit 59f255d

Please sign in to comment.