1
+ """ /*
2
+ * EJERCICIO:
3
+ * Utilizando un mecanismo de peticiones HTTP de tu lenguaje, realiza
4
+ * una petición a la web que tú quieras, verifica que dicha petición
5
+ * fue exitosa y muestra por consola el contenido de la web.
6
+ *
7
+ * DIFICULTAD EXTRA (opcional):
8
+ * Utilizando la PokéAPI (https://pokeapi.co), crea un programa por
9
+ * terminal al que le puedas solicitar información de un Pokémon concreto
10
+ * utilizando su nombre o número.
11
+ * - Muestra el nombre, id, peso, altura y tipo(s) del Pokémon
12
+ * - Muestra el nombre de su cadena de evoluciones
13
+ * - Muestra los juegos en los que aparece
14
+ * - Controla posibles errores
15
+ */ """
16
+
17
+ import requests
18
+
19
+ #EJERCICIO
20
+
21
+ """ response = requests.get("http://www.google.es")
22
+ if response.status_code == 200:
23
+ print(response.text)
24
+ print(response)
25
+ else:
26
+ (f"Error con código {response.status_code} al utilizar la petición.") """
27
+
28
+ #DIFICULTAD EXTRA
29
+
30
+ pokemon = input ("Introduce el nombre o número del Pokemon a buscar:" ).lower ()
31
+
32
+ response_pokemon = requests .get (f"https://pokeapi.co/api/v2/pokemon/{ pokemon } /" )
33
+ if response_pokemon .status_code == 200 :
34
+ data = response_pokemon .json ()
35
+ print (f"\n ID: " , data ["id" ])
36
+ print (f"Nombre: " , data ["name" ])
37
+ print (f"Peso: " , data ["weight" ])
38
+ print (f"Altura: " , data ["height" ])
39
+ for type in data ["types" ]:
40
+ print ("Tipo: " , type ["type" ]["name" ])
41
+
42
+ response_pokemon = requests .get (f"https://pokeapi.co/api/v2/pokemon-species/{ pokemon } /" )
43
+ if response_pokemon .status_code == 200 :
44
+ url = response_pokemon .json ()["evolution_chain" ]["url" ]
45
+
46
+ response_pokemon = requests .get (url )
47
+
48
+ if response_pokemon .status_code == 200 :
49
+ data = response_pokemon .json ()
50
+
51
+ print ("\n Cadena de evoluciones:" )
52
+
53
+ def get_evolves (data ):
54
+
55
+ print (data ["species" ]["name" ])
56
+ if "evolves_to" in data :
57
+ for evolve in data ["evolves_to" ]:
58
+ get_evolves (evolve )
59
+
60
+ get_evolves (data ["chain" ])
61
+
62
+ else :
63
+ print ("Error" )
64
+
65
+ else :
66
+ print ("Error." )
67
+
68
+ print ("\n Listado de juegos:" )
69
+ response_pokemon = requests .get (f"https://pokeapi.co/api/v2/pokemon/{ pokemon } /" )
70
+ if response_pokemon .status_code == 200 :
71
+ data = response_pokemon .json ()
72
+ for game in data ["game_indices" ]:
73
+ print (game ["version" ]["name" ])
74
+ else :
75
+ print ("Error." )
76
+
77
+ else :
78
+ print ("Error, pokemon no encontrado." )
0 commit comments