forked from Nikhil0504/CCT-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AvailableBeds.py
83 lines (62 loc) · 2.05 KB
/
AvailableBeds.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
78
79
80
81
82
83
import discord, requests, time, os
token = os.getenv("DISCORD_TOKEN")
client = discord.Client()
@client.event
async def on_ready():
print("\nWe have logged in as {0.user}".format(client))
data = {}
district_list = {}
def districts(message, state, api):
if state not in district_list:
temp = set()
data[state] = requests.get(api).json()
for i in data[state]:
temp.add(i["DISTRICT"])
district_list[state] = sorted(list(temp))
temp = district_list[state]
embed = discord.Embed(
title="Select a district",
description="Format: -data [state] [district]",
url=discord.embeds.EmptyEmbed,
)
for i in temp:
embed.add_field(
name=i, value="-data {} {}".format(state, i.replace(" ", "").lower())
)
return embed
@client.event
async def on_message(message):
if message.content.lower() == "-tamilnadu":
await message.channel.send(
embed=districts(
message,
"tamilnadu",
"https://api.covidbedsindia.in/v1/storages/6089820e03eef3b588d05a6d/Tamil%20Nadu",
)
)
elif message.content.lower() == "-andhrapradesh":
await message.channel.send(
embed=districts(
message,
"andhrapradesh",
"https://api.covidbedsindia.in/v1/storages/608982e003eef31f34d05a71/Andhra%20Pradesh",
)
)
elif message.content.lower().startswith("-data "):
temp = message.content.split(" ")
flag = False
if len(temp) < 3:
flag = True
for i in data[temp[1]]:
if flag == False:
if i["DISTRICT"].replace(" ", "").lower() != temp[2].lower():
continue
embed = discord.Embed(name=i["HOSPITAL_NAME"])
for j in i:
embed.add_field(name=j, value=i[j])
await message.channel.send(embed=embed)
client.run(token)
while True:
time.sleep(7200)
district_list = {}
data = {}