21 lines
827 B
Python
21 lines
827 B
Python
def get_quote():
|
|
try:
|
|
response = requests.get(API_URL, timeout=10)
|
|
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(f"CITAT: {quote}")
|
|
print(f"AUTOR: {author}")
|
|
with open("quote.txt", "w") as f:
|
|
f.write(f"📜 *\"{quote}\"* \n\n✍️ **{author}**")
|
|
except Exception as e:
|
|
print(f"Eroare la apelarea API-ului: {e}")
|
|
sys.exit(1) |