-
Notifications
You must be signed in to change notification settings - Fork 0
/
pokemon.py
146 lines (102 loc) · 5.63 KB
/
pokemon.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from termcolor import colored
import requests
print(colored("\nBienvenido al mundo pokemon\n","blue"))
print(colored("Opción 1: Listar pokemons por generación","magenta"))
print(colored("Opción 2: Listar pokemons por forma","magenta"))
print(colored("Opción 3: Listar pokemons por habilidad","magenta"))
print(colored("Opción 4: Listar pokemons por habitat","magenta"))
print(colored("Opción 5: Listar pokemons por tipo","magenta"))
chooseOption = input("\nElige una de las opciones(1,2,3,4,5): ")
while chooseOption not in ("1", "2", "3", "4", "5"):
chooseOption = input("\nElige una de las opciones(1,2,3,4,5): ")
if chooseOption == "1":
input_gen = input(colored("Qué generación de pokemons quieres ver (1,2,3,4,5,6,7 u 8)?: ", "blue"))
while input_gen not in ("1", "2", "3", "4", "5","6","7","8"):
input_gen = input(colored("Qué generación de pokemons quieres ver (1,2,3,4,5,6,7 u 8)?: ", "blue"))
def generations(numGen):
if __name__ == '__main__':
url_gen = "https://pokeapi.co/api/v2/generation/" + numGen
response_gen = requests.get(url_gen)
if response_gen.status_code == 200:
payload_gen = response_gen.json()
pokemon_species = payload_gen.get('pokemon_species', [])
if pokemon_species:
for pokemon_gen in pokemon_species:
name_gen = pokemon_gen['name']
print(name_gen)
generations(input_gen)
elif chooseOption == "2":
print("Has elegido las formas")
elif chooseOption == "3":
print("Estas son las habilidades de los pokemones: ")
def pokemon_abilities(url_abil = 'https://pokeapi.co/api/v2/ability/', offset = 0):
args = {'offset' : offset} if offset else {}
response_abil = requests.get(url_abil, params=args)
if response_abil.status_code == 200:
payload_abil = response_abil.json()
results_abil = payload_abil.get('results', [])
if results_abil:
for pokemon_abil in results_abil:
name_abil = pokemon_abil['name']
print(name_abil)
#AGREGAR UN IF PARA TRAER LOS POKEMS DE CIERTAS HABILIDADES
next_abilities = input("Continuar listando? [Y/N]: ").lower()
if next_abilities == "y":
pokemon_abilities(offset=offset+20)
else:
pokemon_abilities = int(input("Ingresa una de las habilidades para mostrar los pokemons con dicha habilidad(1,2,3,...327): "))
def results_abilities(numabilities):
url_results_abilities = "https://pokeapi.co/api/v2/pokemon-habitat/" + str(numabilities)
response_results_abilities = requests.get(url_results_abilities)
if response_results_abilities.status_code == 200:
payload_results_abilities = response_results_abilities.json()
pokemon_results_abilities = payload_results_abilities.get('results', [])
if pokemon_results_abilities:
for pokemon_results_abilities in pokemon_results_abilities:
name_results_abilities = pokemon_results_abilities['name']
print(name_results_abilities)
results_abilities(pokemon_abilities)
if __name__ == '__main__':
url_abil = "https://pokeapi.co/api/v2/ability/"
pokemon_abilities()
elif chooseOption == "4":
input_habit = int(input(colored("Qué habitat de pokemons quieres ver (1,2,3,4,5,6,7,8)?: ", "blue")))
while input_habit not in (1, 2, 3, 4, 5,6,7,8):
input_habit = int(input(colored("Qué habitat de pokemons quieres ver (0,1,2,3,4,5,6,7,8 )?: ", "blue")))
def results_habitats(numHabit):
url_results_habitats = "https://pokeapi.co/api/v2/pokemon-habitat/"
response_results_habitats = requests.get(url_results_habitats)
if response_results_habitats.status_code == 200:
payload_results_habitats = response_results_habitats.json()
pokemon_results_habitats = payload_results_habitats.get('results', [])
print(pokemon_results_habitats[numHabit])
results_habitats(input_habit)
def habitats(numGen):
if __name__ == '__main__':
url_gen = "https://pokeapi.co/api/v2/pokemon-habitat/" + str(numGen)
response_habit = requests.get(url_gen)
if response_habit.status_code == 200:
payload_gen = response_habit.json()
pokemon_species = payload_gen.get('pokemon_species', [])
if pokemon_species:
for pokemon_gen in pokemon_species:
name_gen = pokemon_gen['name']
print(name_gen)
habitats(input_habit)
elif chooseOption == "5":
print("Has elegido por tipo")
input_type = input(colored("Qué tipo de pokemons quieres ver (1,2,3,4,...,20)?: ", "blue"))
while input_type not in ("1", "2", "3", "4", "5","6","7","8","9"):
input_type = input(colored("Qué tipo de pokemons quieres ver (1,2,3,4,...,20)?: ", "blue"))
def types(numGen):
url_type = "https://pokeapi.co/api/v2/type/" + numGen
response_type = requests.get(url_type)
if response_type.status_code == 200:
payload_type = response_type.json()
pokes = payload_type.get('pokemon', [])
for pokemon_typ in pokes:
name_type = pokemon_typ['pokemon']['name']
print(name_type)
types(input_type)
else:
print("Elige una de las 5 opciones")