Merge branch 'weather' into 'master'

Weather

See merge request ldooks/dragon-bot!44
This commit is contained in:
Luke Robles 2017-09-22 03:53:06 +00:00
commit 8eafaa54ba
3 changed files with 24 additions and 4 deletions

View File

@ -20,6 +20,7 @@ import help_methods
import lewds import lewds
import role_check import role_check
import wallpaper import wallpaper
import weather
import wolfram import wolfram
# Client object # Client object
@ -117,6 +118,12 @@ async def on_message(message):
lewds.get_lewd(channel_name=message.channel.name) 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'): if message.content.startswith('!purge'):
num = 20 num = 20
if len(message.content.split()) > 1: if len(message.content.split()) > 1:

View File

@ -59,7 +59,10 @@ def get_help_message(method):
'This function now outputs the SWEET-ASS picture of the day.', 'This function now outputs the SWEET-ASS picture of the day.',
' Note this picture only changes once a day.', ' Note this picture only changes once a day.',
'\nUsage: !homepage' '\nUsage: !homepage'
] ],
'weather': [
'Returns the weather for the location you entered.',
'\nUsage: !weather Berkeley']
} }
# Print out every help method # Print out every help method

View File

@ -7,8 +7,19 @@ emojis = {'clear sky': ':sunny:', 'scattered clouds': ':partly_sunny:',
'light rain': ':white_sun_rain_cloud:', 'overcast clouds': ':cloud:', 'light rain': ':white_sun_rain_cloud:', 'overcast clouds': ':cloud:',
'broken clouds': ':white_sun_cloud:', 'moderate rain': ':cloud_with_rain:', 'broken clouds': ':white_sun_cloud:', 'moderate rain': ':cloud_with_rain:',
'light snow': ':cloud_snow:', 'few clouds': ':white_sun_small_cloud:'} '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:
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) get_weather(location)
@ -18,8 +29,7 @@ def get_weather(location):
TODO: Replace basic code block with nice looking, bold text w/ emojis TODO: Replace basic code block with nice looking, bold text w/ emojis
""" """
try: try:
openweathermap = OWM('593e0e182f9278a10443da354c4014db') forecaster = openweathermap.three_hours_forecast(message)
forecaster = openweathermap.three_hours_forecast(location)
forecast = forecaster.get_forecast() forecast = forecaster.get_forecast()
reg = forecast.get(0) reg = forecast.get(0)