-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenge_ex9.py
69 lines (51 loc) · 1.84 KB
/
challenge_ex9.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
#!/usr/bin/python3
"""Alta3 Research - astros on ISS"""
import urllib.request
import json
MAJORTOM = 'http://api.open-notify.org/astros.json'
MAJORDD = "http://api.open-notify.org/iss-now.json"
def main():
"""reading json from api"""
# call the api
groundctrl = urllib.request.urlopen(MAJORTOM)
locationctrl = urllib.request.urlopen(MAJORDD)
# strip off the attachement (JSON) and read it
# the problem here, is that it will read out as a string
area = locationctrl.read()
helmet = groundctrl.read()
# show that at this point, our data is str
# we want to convert this to list / dict
print(area)
## print(helmet)
areacomp = json.loads(area.decode("utf-8"))
helmetson = json.loads(helmet.decode("utf-8"))
# this should say str
## print(type(area))
## print(type(helmet))
# this should say dict
## print(type(areacomp))
## print(type(helmetson))
""" print(helmetson["number"])
# this returns a LIST of the people on this ISS
print(helmetson["people"])
# list the FIRST astro in the list
print(helmetson["people"][0])
# list the SECOND astro in the list
print(helmetson["people"][1])
# list the LAST astro in the list
print(helmetson["people"][-1])
# display every item in a list
for astro in helmetson["people"]:
# display what astro is
print(astro)
# display every item in a list
for astro in helmetson["people"]:
# display ONLY the name value associated with astro
print(astro["name"])
"""
# display every item in a list
for astro in helmetson["people"]:
# display ONLY the name value associated with astro
print(astro["name"], 'on the', astro["craft"], print( areacomp["iss_position"]))
if __name__ == "__main__":
main()