Adding raws feature for alex

This commit is contained in:
ein 2021-08-16 09:02:30 -07:00
parent 30ec7d8dda
commit 8f09183295
3 changed files with 44 additions and 0 deletions

View File

@ -53,6 +53,13 @@ async def ask(ctx):
questions.answer_question(ctx.message.content), questions.answer_question(ctx.message.content),
) )
@bot.command(name='raws')
async def raws(ctx):
import weather
await ctx.send(
embed=weather.parse_message(ctx.message.content)
)
@bot.command(name='invite') @bot.command(name='invite')
async def invite(ctx): async def invite(ctx):
# Default to creating the invite to the channel the message was sent in # Default to creating the invite to the channel the message was sent in

View File

@ -6,3 +6,4 @@ pandas
requests requests
wikipedia wikipedia
wolframalpha wolframalpha
pyowm

36
app/weather.py Normal file
View File

@ -0,0 +1,36 @@
from pyowm.owm import OWM
import discord
import os
# import pprint
# pp = pprint.PrettyPrinter(indent=4)
def parse_message(message):
location = message.split()[1:]
print(location)
return get_weather(' '.join(location))
def get_weather(location):
# owm = OWM('614e00c15660f75756544b83d556fe75')
owm = OWM(os.getenv('weather_api_key'))
mgr = owm.weather_manager()
observation = mgr.weather_at_place(location) # the observation object is a box containing a weather object
weather = observation.weather
wind_data = weather.wind(unit='miles_hour')
wind_speed = wind_data['speed']
wind_direction = degToCompass(wind_data['deg'])
embed = discord.Embed(description="Weather for %s" % location, color=5793266, type="rich")
embed.add_field(name='Current weather', value=weather.detailed_status, inline=False)
embed.add_field(name='Wind', value="**Wind Speed**: %s, **Wind Direction**: %s" % (wind_speed, wind_direction), inline=False)
embed.add_field(name='Temperature (F)', value=weather.temperature('fahrenheit'), inline=False)
embed.add_field(name='Humidity', value=str(weather.humidity) + '%', inline=False)
return embed
def degToCompass(num):
val=int((num/22.5)+.5)
arr=["N","NNE","NE","ENE","E","ESE", "SE", "SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"]
return arr[(val % 16)]