35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
import requests
|
|
import os
|
|
import sys
|
|
|
|
API_URL = os.getenv("QUOTE_API_URL", "https://api.quotable.io/random")
|
|
|
|
def get_quote():
|
|
try:
|
|
# Folosim verify=False doar dacă avem în continuare erori de SSL pe serverul Jenkins
|
|
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 found."
|
|
author = data.get('author') or data.get('a') or "Unknown Author"
|
|
|
|
# Mesaj formatat pentru Discord
|
|
full_message = f"📜 *\"{quote}\"* \n\n✍️ **{author}**"
|
|
|
|
# Salvăm în folderul /app (care este mapat cu volumul Jenkins)
|
|
with open("/app/quote.txt", "w", encoding="utf-8") as f:
|
|
f.write(full_message)
|
|
|
|
print(f"Succes! Citat salvat: {author}")
|
|
|
|
except Exception as e:
|
|
print(f"Eroare: {e}")
|
|
with open("/app/quote.txt", "w", encoding="utf-8") as f:
|
|
f.write("⚠️ Nu am putut prelua citatul, dar aplicația a rulat.")
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
get_quote() |