janky fix to handle messages

This commit is contained in:
Jason Ji 2017-09-21 18:40:46 -07:00
parent df156c351b
commit 6ab5197242

View File

@ -11,8 +11,12 @@ openweathermap = OWM('593e0e182f9278a10443da354c4014db')
def parse_loc(message):
if len(message.split()) > 1:
return ' '.join(message.split()[1:])
return '```Please input a location: !weather [location]```'
try:
res = get_weather(' '.join(message.split()[1:]))
except exceptions.api_call_error.APICallError:
res = '```Please input a valid location: !weather [location]```'
return res
return '```Please input a valid location: !weather [location]```'
def get_weather(message):
@ -24,9 +28,8 @@ def get_weather(message):
TODO: Replace basic code block with nice looking, bold text w/ emojis
"""
loc = parse_loc(message)
try:
forecaster = openweathermap.three_hours_forecast(loc)
forecaster = openweathermap.three_hours_forecast(message)
forecast = forecaster.get_forecast()
reg = forecast.get(0)