Skip to content

#20 - python #3807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Roadmap/20 - PETICIONES HTTP/python/pyramsd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import requests
from colorama import Fore

query = requests.get('https://comandos-de-linux.reflex.run/')

statusCode = query.status_code

if statusCode == 200:
print(Fore.GREEN + "[+] Petición exitosa" + Fore.RESET)
print(query.content.decode('utf-8'))
else:
print(Fore.RED + "[-] Algo salió mal!" + Fore.RESET)

'''
EXTRA
'''
baseURL = "https://pokeapi.co/api/v2/pokemon"
def getDataPokemon(name):
url = baseURL + "/" + name
try:
query = requests.get(url)
query.raise_for_status()
data = query.json()

print(f"Name: {data['name']}")
print(f"ID: {data['id']}")
print(f"Weight: {data['weight']}")
print(f"Height: {data['height']}")
print(f"Types: {''.join([i['type']['name'] for i in data['types']])}")
print(f"Games: {[game['version']['name'] for game in data['game_indices']]}")


except requests.exceptions.HTTPError as e:
if query.status_code == 404:
print(Fore.RED + f"[-] Error 404: Pokemon '{name}' Not found" + Fore.RESET)

name = input("Nombre de pokemon: ")
getDataPokemon(name)