diff --git a/Retos/Reto #10 - LA API [Media]/python/restevean.py b/Retos/Reto #10 - LA API [Media]/python/restevean.py new file mode 100644 index 0000000000..dca65519ef --- /dev/null +++ b/Retos/Reto #10 - LA API [Media]/python/restevean.py @@ -0,0 +1,55 @@ +""" +Exercise +""" +import requests + + +def get_pokemon_data(pokemon_identifier): + base_url = "https://pokeapi.co/api/v2/pokemon/" + url = f"{base_url}{pokemon_identifier.lower()}" + + response = requests.get(url) + + if response.status_code != 200: + print( + f"Error: No se pudo obtener información para {pokemon_identifier}. Código de estado: {response.status_code}") + return + + data = response.json() + print(f"Name: {data['name'].capitalize()}") + print(f"ID: {data['id']}") + print(f"Weight: {data['weight']/10} kg") + print(f"Height: {data['height']*10} cm") + + types = [type_info['type']['name'] for type_info in data['types']] + print(f"Tipe(s): {', '.join(types).capitalize()}") + + # Obtener cadena de evoluciones + species_url = data['species']['url'] + species_response = requests.get(species_url) + species_data = species_response.json() + evolution_chain_url = species_data['evolution_chain']['url'] + + evolution_chain_response = requests.get(evolution_chain_url) + evolution_chain_data = evolution_chain_response.json() + + evolution_chain = [] + current_evolution = evolution_chain_data['chain'] + + while current_evolution: + evolution_chain.append(current_evolution['species']['name'].capitalize()) + if current_evolution['evolves_to']: + current_evolution = current_evolution['evolves_to'][0] + else: + current_evolution = None + + print(f"Evolutions chain: {', '.join(evolution_chain)}") + + # Obtener juegos en los que aparece + games = [game_info['version']['name'] for game_info in data['game_indices']] + print(f"Games where it appears: {', '.join(games).capitalize()}") + + +if __name__ == '__main__': + pokemon_name = input("Type pokemon's name or number: ") + get_pokemon_data(pokemon_name) diff --git "a/Retos/Reto #11 - URL PARAMS [F\303\241cil]/python/restevean.py" "b/Retos/Reto #11 - URL PARAMS [F\303\241cil]/python/restevean.py" new file mode 100644 index 0000000000..0029d223af --- /dev/null +++ "b/Retos/Reto #11 - URL PARAMS [F\303\241cil]/python/restevean.py" @@ -0,0 +1,35 @@ +""" +Exercise +""" + + +def get_url_parameters(url): + # Split the URL into the base part and the query string + parts = url.split('?') + + # If there are no parameters, return an empty list + if len(parts) < 2: + return [] + + # Get the query string part + query_string = parts[1] + + # Split the query string into key-value pairs + pairs = query_string.split('&') + + # Extract the values from the key-value pairs + values = [] + for pair in pairs: + key_value = pair.split('=') + if len(key_value) == 2: + values.append(key_value[1]) + else: + values.append('') + + return values + + +if __name__ == '__main__': + url = "https://retosdeprogramacion.com?year=2023&challenge=0" + parameters = get_url_parameters(url) + print(parameters)