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, verify=True) 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 found." author = data.get('author') or data.get('a') or "Unknown Author" # 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}") # Î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()