pj2
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import requests
|
||||
import os
|
||||
import sys
|
||||
|
||||
API_URL = os.getenv("QUOTE_API_URL", "https://api.quotable.io/random")
|
||||
|
||||
def get_quote():
|
||||
try:
|
||||
response = requests.get(API_URL, timeout=10)
|
||||
response.raise_for_status()
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
# Dacă API-ul returnează o listă (ca ZenQuotes), luăm primul element
|
||||
if isinstance(data, list):
|
||||
data = data[0]
|
||||
|
||||
# Căutăm citatul și autorul în mai multe locuri posibile
|
||||
quote = data.get('content') or data.get('advice') or data.get('q') or "Citatul nu a putut fi găsit."
|
||||
author = data.get('author') or data.get('a') or "Autor necunoscut"
|
||||
|
||||
print("-" * 30)
|
||||
print(f"CITAT: {data['content']}")
|
||||
print(f"AUTOR: {data['author']}")
|
||||
print(f"CITAT: {quote}")
|
||||
print(f"AUTOR: {author}")
|
||||
print("-" * 30)
|
||||
except Exception as e:
|
||||
print(f"Eroare la apelarea API-ului: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
get_quote()
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user