-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_poke_info.py
58 lines (47 loc) · 1.7 KB
/
get_poke_info.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
import requests
import json
import pprint
"""
aims of exercise:
-return one pokemon dict from pokeapi
"""
def get_poke_info(pokemon_name):
poke_url = "https://pokeapi.co/api/v2/pokemon/" + pokemon_name
response = requests.get(url=poke_url)
unfiltered_poke_dict = response.json()
poke_dict = {}
for key in unfiltered_poke_dict:
if key in ["height", "name", "weight"]:
poke_dict[key] = unfiltered_poke_dict[key]
elif key == "moves":
moves = []
for move in unfiltered_poke_dict[key]:
move_name = move["move"]["name"]
moves.append(move_name)
poke_dict[key] = moves
elif key == "stats":
stats = []
for stat in unfiltered_poke_dict[key]:
base_stat = stat["base_stat"]
stat_name = stat["stat"]["name"]
stats.append({stat_name: base_stat})
poke_dict[key] = stats
elif key == "types":
types = []
for type in unfiltered_poke_dict[key]:
type_name = type["type"]["name"]
types.append(type_name)
poke_dict[key] = types
return poke_dict
if __name__ == "__main__":
p = pprint.PrettyPrinter(indent=4)
p.pprint(get_poke_info("ditto"))
p.pprint(get_poke_info("pikachu"))
p.pprint(get_poke_info("articuno"))
# height ✅
# moves - list of dicts, with dict value containing "name" key we want the value of ✅
# name ✅
# stats - list of dicts, with "base_stat" containing an int,
# and "stat" cont a dict with a "name" key we want ✅
# type - list of dicts, with "type" key cont another dict, with "name" key in it ✅
# weight ✅