-
Notifications
You must be signed in to change notification settings - Fork 0
/
people.py
38 lines (26 loc) · 1013 Bytes
/
people.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
import requests
async def people(ctx):
"""
Returns a message contaning the people in space and what
spacecraft they are aboard.
"""
space_get = requests.get('http://api.open-notify.org/astros.json',
timeout=3
)
space_response = space_get.json()
my_data = {}
for item in space_response['people']:
if not my_data.get(item['craft']):
my_data[item['craft']] = [item['name']]
continue
my_data[item['craft']].append(item['name'])
total_counter = 0
stations, current = '', ''
for station, names in my_data.items():
total_counter += len(names)
current = f"{len(names)} on board the {station}:\n"
for name in names:
current += f"-{name}\n"
stations += f"{current}\n"
total = f"There are currently {space_response['number']} people in space on board the following spacecrafts\n\n{stations}"
await ctx.respond(total)