Skip to content

Commit 717edc0

Browse files
committed
reto 20 didacdev
1 parent 0cbcb14 commit 717edc0

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import requests as re
2+
3+
4+
def check_connection():
5+
try:
6+
r = re.get("https://retosdeprogramacion.com")
7+
print("La petición fue existosa")
8+
except Exception as e:
9+
print(f"Error: {e}")
10+
11+
12+
def get_pokemon(identifier: str):
13+
try:
14+
r = re.get(f"https://pokeapi.co/api/v2/pokemon/{identifier}")
15+
r_json = r.json()
16+
17+
types = r_json['types']
18+
19+
print(f"\nID: {r_json['id']}")
20+
print(f"Nombre: {r_json['name']}")
21+
print(f"Peso: {r_json['weight']} libras")
22+
print(f"Altura: {r_json['height']} pies")
23+
print(f"Tipos:")
24+
for type in types:
25+
print(f" - {get_type(type['type']['url'])}")
26+
27+
except Exception as e:
28+
print("El Pokemon o ID no son válidos")
29+
30+
31+
def get_type(url: str):
32+
r = re.get(url)
33+
r_json = r.json()
34+
return r_json['name']
35+
36+
37+
def main():
38+
finish = False
39+
40+
while not finish:
41+
42+
print("\nSelecciona una opción:\n"
43+
"1 - Introducir nombre o ID del Pokemon\n"
44+
"2 - Salir")
45+
option = int(input("> "))
46+
47+
match option:
48+
case 1:
49+
print("\nEscribe el nombre o identificador del Pokemon")
50+
identifier = input("> ")
51+
get_pokemon(identifier)
52+
case 2:
53+
finish = True
54+
print("Hasta pronto 👋")
55+
case _:
56+
print("⚠️ Opción seleccionada no válida")
57+
58+
59+
if __name__ == '__main__':
60+
main()

0 commit comments

Comments
 (0)