1+ import requests # pip install requests
2+
3+ YT_URL = "https://www.youtube.com"
4+
5+ try :
6+ response = requests .get (YT_URL )
7+ if response .status_code == 200 : # 200 -> OK
8+ print ("Petición exitosa!" )
9+ print (response .text [:128 ]) # Imprimir los primeros 128 caracteres de la pagina
10+
11+ except requests .exceptions .RequestException as e :
12+ print (e )
13+ print ("\n " )
14+
15+ # ---- DIFICULTAD EXTRA ----
16+
17+ pokeAPI = "https://pokeapi.co/api/v2/pokemon/"
18+
19+ busqueda = input ("Ingrese el nombre o id de un pokemon => " )
20+
21+ try :
22+ response = requests .get (pokeAPI + busqueda )
23+ response .raise_for_status ()
24+ data = response .json ()
25+
26+ except Exception as e :
27+ print (e )
28+
29+ else :
30+ print ("Nombre: " + data ["name" ])
31+ print ("ID: " + str (data ["id" ]))
32+ print ("Peso: " + str (data ["weight" ]))
33+ print ("Altura: " + str (data ["height" ]))
34+ print ("Tipos: " + ", " .join ([tipo ["type" ]["name" ] for tipo in data ["types" ]]))
35+
36+ print ("\n " )
37+
38+ especies_data = requests .get (data ["species" ]["url" ]).json ()
39+ cadena_evolucion_data = requests .get (especies_data ["evolution_chain" ]["url" ]).json ()
40+
41+ evoluciones = [cadena_evolucion_data ["chain" ]["species" ]["name" ]]
42+ ev = cadena_evolucion_data ["chain" ]["evolves_to" ]
43+ is_evolve = ev != []
44+
45+ while is_evolve :
46+ evoluciones .append (ev [0 ]["species" ]["name" ])
47+ ev = ev [0 ]["evolves_to" ]
48+ is_evolve = ev != []
49+
50+ print ("Cadena de evolución: " + " -> " .join (evoluciones ))
51+ print ("Aparicion en juegos: " + ", " .join ([i ["version" ]["name" ] for i in data ["game_indices" ]]))
0 commit comments