This commit is contained in:
Ionel Andrei Cataon
2026-02-12 17:13:45 +02:00
parent 84fe05d110
commit 2e1da76f1f
2 changed files with 23 additions and 17 deletions

View File

@@ -1,22 +1,28 @@
import requests import requests
import json
def get_quote(): def get_quote():
url = "https://api.quotable.io/random"
try: try:
# Schimbăm la Quotable pentru a primi autorul print(f"Connecting to {url}...")
response = requests.get("https://api.quotable.io/random", timeout=10) response = requests.get(url, timeout=15)
response.raise_for_status() response.raise_for_status()
data = response.json() data = response.json()
quote = data.get('content', 'No quote found') content = data.get('content', 'No content')
author = data.get('author', 'Unknown') author = data.get('author', 'Unknown Author')
output = f"📜 *\"{content}\"*\n\n✍️ **Autor:** {author}"
# Formatăm textul care va ajunge pe Discord
with open("quote.txt", "w", encoding="utf-8") as f: with open("quote.txt", "w", encoding="utf-8") as f:
f.write(f"📜 *\"{quote}\"*\n\n✍️ **Autor:** {author}") f.write(output)
print("Success: Quote and Author saved.")
except Exception as e: except Exception as e:
error_msg = f"⚠️ Eroare API: {str(e)}"
print(error_msg)
with open("quote.txt", "w", encoding="utf-8") as f: with open("quote.txt", "w", encoding="utf-8") as f:
f.write(f"⚠️ Eroare la preluare: {str(e)}") f.write(error_msg)
if __name__ == "__main__": if __name__ == "__main__":
get_quote() get_quote()

View File

@@ -19,15 +19,15 @@ pipeline {
script { script {
dir('project2') { dir('project2') {
sh "docker rm -f quotes-worker || true" sh "docker rm -f quotes-worker || true"
try { // Rulăm și afișăm log-urile containerului
// ADAUGĂM --dns 8.8.8.8 aici pentru a rezolva eroarea din Build #35 sh "docker run --name quotes-worker --dns 8.8.8.8 quotes-app"
sh "docker run --name quotes-worker --dns 8.8.8.8 quotes-app" sh "docker logs quotes-worker"
sh "docker cp quotes-worker:/app/quote.txt ."
} catch (e) { sh "docker cp quotes-worker:/app/quote.txt ."
echo "⚠️ Eroare la execuție: ${e.message}"
} finally { // DEBUG: Vedem ce e în fișier direct în Jenkins
sh "docker rm -f quotes-worker || true" echo "Conținut fișier extras:"
} sh "cat quote.txt"
} }
} }
} }