diff --git a/app/weather.py b/app/weather.py index e502eeb5..233766cb 100644 --- a/app/weather.py +++ b/app/weather.py @@ -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)