import requests import os import sys # Folosim variabila de mediu sau un fallback API_URL = os.getenv("QUOTE_API_URL", "https://api.quotable.io/random") def get_quote(): try: # Timeout de 10 secunde ca să nu stea Jenkins blocat dacă API-ul nu răspunde response = requests.get(API_URL, timeout=10) response.raise_for_status() data = response.json() if isinstance(data, list): data = data[0] quote = data.get('content') or data.get('advice') or data.get('q') or "No quote today." author = data.get('author') or data.get('a') or "Unknown" # Mesaj formatat pentru Discord message = f"📜 *\"{quote}\"* \n\n✍️ **{author}**" with open("quote.txt", "w", encoding="utf-8") as f: f.write(message) print(f"Citat salvat cu succes!") except Exception as e: print(f"Eroare API: {e}") with open("quote.txt", "w", encoding="utf-8") as f: f.write("⚠️ Nu am putut prelua citatul din cauza unei erori de rețea.") # Ieșim cu 0 ca să lăsăm Jenkins să trimită notificarea chiar dacă API-ul a dat fail sys.exit(0) if __name__ == "__main__": get_quote()