From 4a59bd05064d0debe7b2a683f85855242f1f11cf Mon Sep 17 00:00:00 2001 From: Jason Ji Date: Thu, 21 Sep 2017 18:30:34 -0700 Subject: [PATCH] handle string inputs --- app/weather.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/weather.py b/app/weather.py index 311ae871..c57e32be 100644 --- a/app/weather.py +++ b/app/weather.py @@ -7,8 +7,15 @@ emojis = {'clear sky': ':sunny:', 'scattered clouds': ':partly_sunny:', 'light rain': ':white_sun_rain_cloud:', 'overcast clouds': ':cloud:', 'broken clouds': ':white_sun_cloud:', 'moderate rain': ':cloud_with_rain:', 'light snow': ':cloud_snow:', 'few clouds': ':white_sun_small_cloud:'} +openweathermap = OWM('593e0e182f9278a10443da354c4014db') -def get_weather(location): +def parse_loc(message): + if len(message.split()) > 1: + return ' '.join(message.split()[1:]) + return '```Please input a location: !weather [location]```' + + +def get_weather(message): """ get_weather(location) @@ -17,8 +24,8 @@ def get_weather(location): TODO: Replace basic code block with nice looking, bold text w/ emojis """ + loc = parse_loc(message) try: - openweathermap = OWM('593e0e182f9278a10443da354c4014db') forecaster = openweathermap.three_hours_forecast(location) forecast = forecaster.get_forecast()