This commit is contained in:
Ionel Andrei Cataon
2026-02-12 16:38:57 +02:00
parent 04f2f26561
commit 8713c62e82
2 changed files with 45 additions and 18 deletions

View File

@@ -1,21 +1,34 @@
import requests
import os
import sys
# Luăm URL-ul din variabila de mediu sau folosim unul default
API_URL = os.getenv("QUOTE_API_URL", "https://api.quotable.io/random")
def get_quote():
try:
response = requests.get(API_URL, timeout=10)
response = requests.get(API_URL, timeout=10, verify=True)
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"
quote = data.get('content') or data.get('advice') or data.get('q') or "No quote found."
author = data.get('author') or data.get('a') or "Unknown Author"
print(f"CITAT: {quote}")
print(f"AUTOR: {author}")
with open("quote.txt", "w") as f:
# Afișăm în consola Jenkins pentru debug
print(f"Citat extras: {quote} - {author}")
with open("quote.txt", "w", encoding="utf-8") as f:
f.write(f"📜 *\"{quote}\"* \n\n✍️ **{author}**")
except Exception as e:
print(f"Eroare la apelarea API-ului: {e}")
sys.exit(1)
# În caz de eroare, scriem un mesaj de fallback în fișier
with open("quote.txt", "w", encoding="utf-8") as f:
f.write(f"⚠️ Nu am putut recupera citatul, dar build-ul a reușit.")
sys.exit(1)
if __name__ == "__main__":
get_quote()