-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
77 lines (59 loc) · 2 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import json
import discord
import requests
from continuity import continuity
intent = discord.Intents.default()
intent.members = True
intent.message_content = True
client = discord.Client(intents=intent)
def weather(city):
try:
rooturl = "http://api.openweathermap.org/data/2.5/weather?"
api_key = os.getenv("api_key")
url = f"{rooturl}q={city}&apikey={api_key}&units=metric"
r = requests.get(url)
data = r.json()
city = data['name']
temp = data['main']['temp']
temp2 = data['main']['feels_like']
temp3 = data['main']['humidity']
temp4 = data['weather'][0]['description']
temp5 = data['sys']['country']
embed = discord.Embed(title=f"{city}"
' Weather',
description=f"{temp4.capitalize()}",
color=0x14aaeb)
embed.add_field(name="Temperature: ", value=f"{temp:.0f}°C", inline=True)
embed.add_field(name="Feels like: ", value=f"{temp2:.0f}°C", inline=True)
embed.add_field(name="Humidity: ", value=f"{temp3}%", inline=True)
embed.add_field(name="Country: ", value=f"{temp5}", inline=True)
return embed
except:
embed = discord.Embed(title="Invalid location...", color=0x14aaeb)
embed.add_field(
name="Error...",
value=
"The weather information for this city is unavailable, please enter another city name.",
inline=True)
return embed
def quotes():
response = requests.get("https://zenquotes.io/api/random")
json_data = json.loads(response.text)
quote = json_data[0]['q'] + " \n- " + json_data[0]['a']
return (quote)
@client.event
async def on_ready():
print('Logged in as {0.user}'.format(client))
@client.event
async def on_message(msg):
if msg.author == client.user:
return
if msg.content.startswith("#morning"):
quote = quotes()
city = msg.content[9::].lower()
data = weather(city)
await msg.channel.send(quote)
await msg.channel.send(embed=data)
continuity()
client.run(os.getenv('token'))