From 5310b0d7db2b74f8a5fa3a061f2bd5cbe83e6567 Mon Sep 17 00:00:00 2001 From: Jason Ji Date: Thu, 21 Sep 2017 18:06:35 -0700 Subject: [PATCH 01/10] shoot me in the face i forgot to add this --- app/dragon-bot.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 191cd2d7..00bf8e16 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -20,6 +20,7 @@ import help_methods import lewds import role_check import wallpaper +import weather import wolfram # Client object @@ -116,6 +117,12 @@ async def on_message(message): lewds.get_lewd(channel_name=message.channel.name) ) + if message.content.startswith('!weather'): + await client.send_message( + message.channel, + weather.get_weather(message.content) + ) + if message.content.startswith('!purge'): num = 20 if len(message.content.split()) > 1: From 8771c9e8ab450478d87dd5c3e516ba8e35f56681 Mon Sep 17 00:00:00 2001 From: Jason Ji Date: Fri, 22 Sep 2017 01:18:58 +0000 Subject: [PATCH 02/10] fixed message handling for weather --- app/dragon-bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 71462400..7888a6ba 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -121,7 +121,7 @@ async def on_message(message): if message.content.startswith('!weather'): await client.send_message( message.channel, - weather.get_weather(message.content) + weather.get_weather(message.content.split()[1:]) ) if message.content.startswith('!purge'): From 43003f7a6bb04071a6b20d2fa39cbfafb91df0e5 Mon Sep 17 00:00:00 2001 From: Jason Ji Date: Thu, 21 Sep 2017 18:30:34 -0700 Subject: [PATCH 03/10] 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() From 9e414eac1732c7cd328962a662f177c60d715450 Mon Sep 17 00:00:00 2001 From: Jason Ji Date: Thu, 21 Sep 2017 18:31:34 -0700 Subject: [PATCH 04/10] handling string inputs properly --- app/dragon-bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 7888a6ba..71462400 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -121,7 +121,7 @@ async def on_message(message): if message.content.startswith('!weather'): await client.send_message( message.channel, - weather.get_weather(message.content.split()[1:]) + weather.get_weather(message.content) ) if message.content.startswith('!purge'): From b3434fa898ee28f1268db9555a41faa0a319f457 Mon Sep 17 00:00:00 2001 From: Jason Ji Date: Thu, 21 Sep 2017 18:34:01 -0700 Subject: [PATCH 05/10] fixed variable name issue --- app/weather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/weather.py b/app/weather.py index c57e32be..e502eeb5 100644 --- a/app/weather.py +++ b/app/weather.py @@ -26,7 +26,7 @@ def get_weather(message): """ loc = parse_loc(message) try: - forecaster = openweathermap.three_hours_forecast(location) + forecaster = openweathermap.three_hours_forecast(loc) forecast = forecaster.get_forecast() reg = forecast.get(0) From bfe662ddaa503a75e2275a03f6ba3ec6ff92809c Mon Sep 17 00:00:00 2001 From: Jason Ji Date: Thu, 21 Sep 2017 18:40:46 -0700 Subject: [PATCH 06/10] janky fix to handle messages --- app/weather.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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) From dd6db6b935e54d520925a64fa29a44fc85142291 Mon Sep 17 00:00:00 2001 From: Jason Ji Date: Thu, 21 Sep 2017 19:09:52 -0700 Subject: [PATCH 07/10] updated help for weather --- app/help_methods.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/help_methods.py b/app/help_methods.py index 647e3731..9c3b9fcf 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -59,7 +59,10 @@ def get_help_message(method): 'This function now outputs the SWEET-ASS picture of the day.', ' Note this picture only changes once a day.', '\nUsage: !homepage' - ] + ], + 'weather': [ + 'Returns the weather for the location you entered.', + '\nUsage: !weather Berkeley'] } # Print out every help method From 2249e5a2d10ade5ac05fb995d3db87ea9eef8bf2 Mon Sep 17 00:00:00 2001 From: Jason Ji Date: Thu, 21 Sep 2017 23:51:23 -0700 Subject: [PATCH 08/10] prints emoji for current status weather --- app/weather.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/weather.py b/app/weather.py index 233766cb..bd521db6 100644 --- a/app/weather.py +++ b/app/weather.py @@ -36,8 +36,9 @@ def get_weather(message): location = forecast.get_location().get_name() indicator = int(reg.get_reference_time(timeformat='iso')[11:13]) // 3 - curr_stat = '{}{}{}{}{}'.format(' \n***Status in ', location, ':*** *', - reg.get_detailed_status().title(), '*\n') + curr_stat = '{}{}{}{}{}{}{}'.format(' \n***Status in ', location, ':*** *', + reg.get_detailed_status().title(), '*', + emojis.get(reg.get_detailed_status()), '\n') curr_temp = '{}{}{}'.format('**Current Temperature:** *', str(reg.get_temperature('fahrenheit').get('temp')), 'F*\n\n__**3 day forecast:**__\n') From b34acd125e44a09dd22e72402389e9d9bcf8a835 Mon Sep 17 00:00:00 2001 From: Jason Ji Date: Sun, 24 Sep 2017 11:59:57 -0700 Subject: [PATCH 09/10] code cleanup --- app/weather.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/weather.py b/app/weather.py index bd521db6..5402c595 100644 --- a/app/weather.py +++ b/app/weather.py @@ -23,10 +23,7 @@ def get_weather(message): """ get_weather(location) - Returns the weather forecast for the selected location. Uses PythonOWM to - make life super easy. - - TODO: Replace basic code block with nice looking, bold text w/ emojis + Returns the weather forecast for the selected location. Uses PythonOWM. """ try: forecaster = openweathermap.three_hours_forecast(message) @@ -36,12 +33,12 @@ def get_weather(message): location = forecast.get_location().get_name() indicator = int(reg.get_reference_time(timeformat='iso')[11:13]) // 3 - curr_stat = '{}{}{}{}{}{}{}'.format(' \n***Status in ', location, ':*** *', - reg.get_detailed_status().title(), '*', - emojis.get(reg.get_detailed_status()), '\n') - curr_temp = '{}{}{}'.format('**Current Temperature:** *', - str(reg.get_temperature('fahrenheit').get('temp')), - 'F*\n\n__**3 day forecast:**__\n') + curr_stat = ' \n***Status in {}:*** *{}* {}\n'.format( + location, + reg.get_detailed_status().title(), + emojis[reg.get_detailed_status()]) + curr_temp = '**Currently:** *{}F*\n\n__**3 day forecast:**__\n'.format( + str(reg.get_temperature('fahrenheit').get('temp'))) forecast_str = '{}{}'.format(curr_stat, curr_temp) ind = 0 @@ -62,12 +59,15 @@ def get_weather(message): if low > l: low = l - day = '{}{}{}'.format('***', days_from_ind.get(ind), '***\n') - weather_stat = '{}{}{}{}{}'.format('**Status:** *', + day = '***{}***\n'.format( + days_from_ind.get(ind)) + weather_stat = '**Status:** *{}* {}\n'.format( forecast.get(i).get_detailed_status().title(), - '* ', emojis.get(forecast.get(i).get_detailed_status()), '\n') - high_temp = '{}{}{}'.format('**High:** *', str(high), 'F*\n') - low_temp = '{}{}{}'.format('**Low:** *', str(low), 'F*\n\n') + emojis[forecast.get(i).get_detailed_status()]) + high_temp = '**High:** *{}F*\n'.format( + str(high)) + low_temp = '**Low:** *{}F*\n\n'.format( + str(low)) forecast_str = '{}{}{}{}{}'.format( forecast_str, day, weather_stat, high_temp, low_temp) ind += 1 From a901b0b374ce7f7541f924fb4e95c7a7b837d463 Mon Sep 17 00:00:00 2001 From: Jason Ji Date: Sun, 24 Sep 2017 12:06:45 -0700 Subject: [PATCH 10/10] clean up clean up --- app/weather.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/weather.py b/app/weather.py index 5402c595..73a965f3 100644 --- a/app/weather.py +++ b/app/weather.py @@ -24,6 +24,8 @@ def get_weather(message): get_weather(location) Returns the weather forecast for the selected location. Uses PythonOWM. + + TODO: Create a list of weather preferences - rain > sun, snow > rain, etc. """ try: forecaster = openweathermap.three_hours_forecast(message) @@ -53,7 +55,7 @@ def get_weather(message): temps = day.get_temperature('fahrenheit') h = temps.get('temp_max') l = temps.get('temp_min') - print(forecast.get(i + j).get_detailed_status()) + # print(forecast.get(i + j).get_detailed_status()) if high < h: high = h if low > l: