Skip to content

Commit

Permalink
Reto mouredev#10 - Python
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisRamos98 committed Jun 17, 2024
1 parent ba518d3 commit 6a4ae27
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Retos/Reto #10 - LA API [Media]/python/luisramos98.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3

'''
* Llamar a una API es una de las tareas más comunes en programación.
*
* Implementa una llamada HTTP a una API (la que tú quieras) y muestra su
* resultado a través de la terminal. Por ejemplo: Pokémon, Marvel...
*
* Aquí tienes un listado de posibles APIs:
* https://github.com/public-apis/public-apis
'''

import requests

def text_format(text):
if "setup" in text:
print(f'\n[?] {text["setup"]}\n')
print(f'[+] {text["delivery"]}\n')
else:
print(f'\n[+] {text["joke"]}\n')

def jokes():
url = "https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw"
try:
r = requests.get(url)
text = r.json()
text_format(text)
except Exception as e:
print(f"\n[!] Se ha producido un error: {e}")

def main():
jokes()

if __name__ == '__main__':
main()

0 comments on commit 6a4ae27

Please sign in to comment.