From: zonidjan Date: Fri, 19 Jan 2018 19:04:04 +0000 (-0600) Subject: weather - workaround for python rfc822.parsedate silliness X-Git-Url: https://jfr.im/git/erebus.git/commitdiff_plain/6e8f06d6fd26b75f2ef1b5ee1febc323bb4a6204?hp=d4cfb340ddd9659422ec8a6a3ecf3abf25f00190 weather - workaround for python rfc822.parsedate silliness --- diff --git a/modules/weather.py b/modules/weather.py index 6b50771..b1cd03a 100644 --- a/modules/weather.py +++ b/modules/weather.py @@ -22,6 +22,9 @@ import json, urllib, time, rfc822 def location(person, default=None): return lib.mod('userinfo')._get(person, 'location', default=None) +def _dayofweek(dayname): + return ['mon','tue','wed','thu','fri','sat','sun'].index(dayname.lower()) + def _weather(place): if place is not None: weather = json.load(urllib.urlopen('http://api.wunderground.com/api/8670e6d2e69ff3c7/conditions/q/%s.json' % (place))) @@ -34,7 +37,8 @@ def _weather(place): return "That search term is ambiguous. Please be more specific." current = weather['current_observation'] - measuredat = rfc822.parsedate(current['observation_time_rfc822']) # parsedate_tz returns a 10-tuple which strftime DOESN'T ACCEPT + measuredat = list(rfc822.parsedate(current['observation_time_rfc822'])) + measuredat[6] = _dayofweek(current['observation_time_rfc822'][0:3]) measuredatTZ = current['local_tz_short'] loc = current['observation_location'] if loc['city'] == "" or loc['state'] == "": loc = current['display_location']