Compare commits

...

2 Commits

Author SHA1 Message Date
Brian S. Stephan 56d0e26c6d reimplement !weather in the IRC bot 2019-10-06 09:13:51 -05:00
Brian S. Stephan b42d0ac0e9 pin irc==15.0.6 in requirements 2019-10-05 11:34:28 -05:00
5 changed files with 65 additions and 14 deletions

View File

@ -17,9 +17,8 @@ djangorestframework==3.9.4
dodgy==0.1.9 # via prospector
future==0.17.1 # via parsedatetime
idna==2.8 # via requests
importlib-metadata==0.18 # via irc
inflect==2.1.0 # via jaraco.itertools
irc==17.1
irc==15.0.6
isort==4.3.20 # via pylint
jaraco.classes==2.0 # via jaraco.collections
jaraco.collections==2.0 # via irc
@ -35,7 +34,7 @@ more-itertools==7.0.0 # via irc, jaraco.functools, jaraco.itertools
oauthlib==3.0.1 # via requests-oauthlib
parsedatetime==2.4
pep8-naming==0.4.1 # via prospector
pip-tools==3.8.0
pip-tools==4.1.0
ply==3.11
prospector==1.1.6.4
pycodestyle==2.4.0 # via prospector
@ -55,7 +54,7 @@ requests-oauthlib==1.2.0 # via twython
requests==2.22.0 # via python-gitlab, requests-oauthlib, twython
requirements-detector==0.6 # via prospector
setoptconf==0.2.0 # via prospector
six==1.12.0 # via astroid, django-extensions, jaraco.classes, jaraco.collections, jaraco.itertools, jaraco.logging, jaraco.stream, logilab-common, pip-tools, pydocstyle, python-dateutil, python-gitlab, tempora
six==1.12.0 # via astroid, django-extensions, irc, jaraco.classes, jaraco.collections, jaraco.itertools, jaraco.logging, jaraco.stream, logilab-common, pip-tools, pydocstyle, python-dateutil, python-gitlab, tempora
snowballstemmer==1.2.1 # via pydocstyle
sqlparse==0.3.0 # via django
tempora==1.14.1 # via irc, jaraco.logging
@ -63,7 +62,6 @@ twython==3.7.0
typed-ast==1.4.0 # via astroid
urllib3==1.25.3 # via requests
wrapt==1.11.2 # via astroid
zipp==0.5.1 # via importlib-metadata
# The following packages are considered to be unsafe in a requirements file:
# setuptools==41.0.1 # via logilab-common
# setuptools==41.2.0 # via logilab-common

View File

@ -4,7 +4,7 @@ django-bootstrap3 # bootstrap layout
django-extensions # more commands
django-registration-redux # registration views/forms
djangorestframework # dispatch WS API
irc # core
irc==15.0.6 # core, pinned until I can bother to update --- 17.x has API changes
parsedatetime # relative date stuff in countdown
ply # dice lex/yacc compiler
python-dateutil # countdown relative math

View File

@ -14,9 +14,8 @@ django==2.2.2
djangorestframework==3.9.4
future==0.17.1 # via parsedatetime
idna==2.8 # via requests
importlib-metadata==0.18 # via irc
inflect==2.1.0 # via jaraco.itertools
irc==17.1
irc==15.0.6
jaraco.classes==2.0 # via jaraco.collections
jaraco.collections==2.0 # via irc
jaraco.functools==2.0 # via irc, jaraco.text, tempora
@ -34,9 +33,8 @@ python-mpd2==1.0.0
pytz==2019.1
requests-oauthlib==1.2.0 # via twython
requests==2.22.0 # via python-gitlab, requests-oauthlib, twython
six==1.12.0 # via django-extensions, jaraco.classes, jaraco.collections, jaraco.itertools, jaraco.logging, jaraco.stream, python-dateutil, python-gitlab, tempora
six==1.12.0 # via django-extensions, irc, jaraco.classes, jaraco.collections, jaraco.itertools, jaraco.logging, jaraco.stream, python-dateutil, python-gitlab, tempora
sqlparse==0.3.0 # via django
tempora==1.14.1 # via irc, jaraco.logging
twython==3.7.0
urllib3==1.25.3 # via requests
zipp==0.5.1 # via importlib-metadata

View File

@ -33,7 +33,27 @@ class Weather(Plugin):
if len(queryitems) <= 0:
return
return self.bot.reply(event, weather_summary(queryitems[0]))
weather = weather_summary(queryitems[0])
weather_output = (f"Weather in {weather['location']}: {weather['current']['description']}. "
f"{weather['current']['temp_F']}/{weather['current']['temp_C']}, "
f"feels like {weather['current']['feels_like_temp_F']}/{weather['current']['feels_like_temp_C']}. "
f"Wind {weather['current']['wind_speed']} from the {weather['current']['wind_direction']}. "
f"Visibility {weather['current']['visibility']}. "
f"Precipitation {weather['current']['precipitation']}. "
f"Pressure {weather['current']['pressure']}. "
f"Cloud cover {weather['current']['cloud_cover']}. UV index {weather['current']['uv_index']}. "
f"Today: {weather['today_forecast']['noteworthy']}, "
f"High {weather['today_forecast']['high_F']}/{weather['today_forecast']['high_C']}, "
f"Low {weather['today_forecast']['low_F']}/{weather['today_forecast']['low_C']}. "
f"Tomorrow: {weather['tomorrow_forecast']['noteworthy']}, "
f"High {weather['tomorrow_forecast']['high_F']}/{weather['tomorrow_forecast']['high_C']}, "
f"Low {weather['tomorrow_forecast']['low_F']}/{weather['tomorrow_forecast']['low_C']}. "
f"Day after tomorrow: {weather['day_after_tomorrow_forecast']['noteworthy']}, "
f"High {weather['day_after_tomorrow_forecast']['high_F']}/{weather['day_after_tomorrow_forecast']['high_C']}, "
f"Low {weather['day_after_tomorrow_forecast']['low_F']}/{weather['day_after_tomorrow_forecast']['low_C']}."
)
return self.bot.reply(event, weather_output)
plugin = Weather

View File

@ -19,6 +19,7 @@ def query_wttr_in(query):
def weather_summary(query):
"""Create a more consumable version of the weather report."""
logger.info(f"assembling weather summary for '{query}")
weather_info = query_wttr_in(query)
# get some common/nested stuff once now
@ -28,6 +29,18 @@ def weather_summary(query):
tomorrow_forecast = weather_info['weather'][1]
day_after_tomorrow_forecast = weather_info['weather'][2]
today_notes = [{'code': int(item['weatherCode']), 'desc': item['weatherDesc'][0]['value'] }
for item in today_forecast['hourly']]
today_noteworthy = sorted(today_notes, key=lambda i: i['code'], reverse=True)[0]['desc']
tomorrow_notes = [{'code': int(item['weatherCode']), 'desc': item['weatherDesc'][0]['value'] }
for item in tomorrow_forecast['hourly']]
tomorrow_noteworthy = sorted(tomorrow_notes, key=lambda i: i['code'], reverse=True)[0]['desc']
day_after_tomorrow_notes = [{'code': int(item['weatherCode']), 'desc': item['weatherDesc'][0]['value'] }
for item in day_after_tomorrow_forecast['hourly']]
day_after_tomorrow_noteworthy = sorted(day_after_tomorrow_notes, key=lambda i: i['code'], reverse=True)[0]['desc']
summary = {
'location': query,
'current': {
@ -41,10 +54,32 @@ def weather_summary(query):
'precipitation': f"{current.get('precipMM')} mm",
'visibility': f"{current.get('visibility')} mi",
'wind_speed': f"{current.get('windspeedMiles')} MPH",
'wind_direction': f"{current.get('winddir16Point')}",
'wind_direction': current.get('winddir16Point'),
'pressure': f"{current.get('pressure')} mb",
'uv_index': f"{current.get('uvIndex')}",
'uv_index': current.get('uvIndex'),
},
'today_forecast': {
'high_C': f"{today_forecast.get('maxtempC')}°C",
'high_F': f"{today_forecast.get('maxtempF')}°F",
'low_C': f"{today_forecast.get('mintempC')}°C",
'low_F': f"{today_forecast.get('mintempF')}°F",
'noteworthy': today_noteworthy,
},
'tomorrow_forecast': {
'high_C': f"{tomorrow_forecast.get('maxtempC')}°C",
'high_F': f"{tomorrow_forecast.get('maxtempF')}°F",
'low_C': f"{tomorrow_forecast.get('mintempC')}°C",
'low_F': f"{tomorrow_forecast.get('mintempF')}°F",
'noteworthy': tomorrow_noteworthy,
},
'day_after_tomorrow_forecast': {
'high_C': f"{day_after_tomorrow_forecast.get('maxtempC')}°C",
'high_F': f"{day_after_tomorrow_forecast.get('maxtempF')}°F",
'low_C': f"{day_after_tomorrow_forecast.get('mintempC')}°C",
'low_F': f"{day_after_tomorrow_forecast.get('mintempF')}°F",
'noteworthy': day_after_tomorrow_noteworthy,
},
}
logger.debug(f"results: {summary}")
return summary