From 868ce4be01790762187451981def4d4db66dc139 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Wed, 10 Jun 2020 09:36:12 -0700 Subject: [PATCH] Removing weather entirely --- app/dragon-bot.py | 8 +---- app/help_methods.py | 6 +--- app/weather.py | 79 --------------------------------------------- 3 files changed, 2 insertions(+), 91 deletions(-) delete mode 100644 app/weather.py diff --git a/app/dragon-bot.py b/app/dragon-bot.py index a5e2947d..10ed04f5 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -35,7 +35,7 @@ import set_avatar import stock import tts import wallpaper -# import weather + # Client object client = discord.Client() dragon_environment = os.getenv('DRAGON_ENV') @@ -290,12 +290,6 @@ async def on_message(message): await client.send_message(message.channel, meme_gen.parse_message(message.content)) - # if message.content.startswith('!weather'): - # await client.send_message( - # message.channel, - # weather.parse_loc(message.content) - # ) - if message.content.startswith('!stock'): await client.send_message( message.channel, diff --git a/app/help_methods.py b/app/help_methods.py index ae488009..c5a44d02 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -120,10 +120,6 @@ def get_help_message(method): ' Note this picture only changes once a day.', '\nUsage: !homepage' ], - 'weather': [ - 'Returns the weather for the location you entered.', - '\nUsage: !weather Berkeley' - ], 'pout': [ 'Returns the URL for an anime girl pouting you filthy weeb\n', 'Usage: !pout' @@ -166,7 +162,7 @@ def get_help_message(method): def get_help_embed(client): categories = { 'fun': ['clap', 'redanda', 'birb', 'youtube', 'dog', 'excuse', 'greentext', 'lewd', 'message', 'meme', 'homepage', 'pout', 'roll', 'smug', 'quake', 'wink',], - 'util': ['corona', '8ball', 'decide', 'info', 'icon', 'wallpaper', 'weather', 'stock', 'tts', 'issue'], + 'util': ['corona', '8ball', 'decide', 'info', 'icon', 'wallpaper', 'stock', 'tts', 'issue'], 'users': ['help', 'invite', 'purge', 'roles', 'source', 'minecraft'], 'admin': ['emoji', 'cleanup'] } diff --git a/app/weather.py b/app/weather.py deleted file mode 100644 index 67bd30c4..00000000 --- a/app/weather.py +++ /dev/null @@ -1,79 +0,0 @@ -import requests -from pyowm import OWM -from pyowm import exceptions - -days_from_ind = {0: 'Today', 1: 'Tomorrow', 2: 'Day after tomorrow'} -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 parse_loc(message): - if len(message.split()) > 1: - 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): - """ - 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) - forecast = forecaster.get_forecast() - - reg = forecast.get(0) - location = forecast.get_location().get_name() - indicator = int(reg.get_reference_time(timeformat='iso')[11:13]) // 3 - - 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 - for i in range((4 - indicator) % 8, int((3 * len(forecast)) / 5), 8): - high, low = 0, 100000 - for j in range(0, 8): - if (i + j < (3 * len(forecast)) / 5): - day = forecast.get(i + j) - else: - break - - temps = day.get_temperature('fahrenheit') - h = temps.get('temp_max') - l = temps.get('temp_min') - # print(forecast.get(i + j).get_detailed_status()) - if high < h: - high = h - if low > l: - low = l - - day = '***{}***\n'.format( - days_from_ind.get(ind)) - weather_stat = '**Status:** *{}* {}\n'.format( - forecast.get(i).get_detailed_status().title(), - 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 - - return forecast_str - except Exception: - return 'Please input a valid location'