diff --git a/project2/famousquotes.py b/project2/famousquotes.py index dfd87b0..4d4b139 100644 --- a/project2/famousquotes.py +++ b/project2/famousquotes.py @@ -1,22 +1,28 @@ import requests +import json def get_quote(): + url = "https://api.quotable.io/random" try: - # Schimbăm la Quotable pentru a primi autorul - response = requests.get("https://api.quotable.io/random", timeout=10) + print(f"Connecting to {url}...") + response = requests.get(url, timeout=15) response.raise_for_status() data = response.json() - quote = data.get('content', 'No quote found') - author = data.get('author', 'Unknown') + content = data.get('content', 'No content') + 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: - f.write(f"📜 *\"{quote}\"*\n\n✍️ **Autor:** {author}") - + f.write(output) + print("Success: Quote and Author saved.") + except Exception as e: + error_msg = f"⚠️ Eroare API: {str(e)}" + print(error_msg) 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__": get_quote() \ No newline at end of file diff --git a/project2/jenkinsfile b/project2/jenkinsfile index 338ff72..d8363ef 100644 --- a/project2/jenkinsfile +++ b/project2/jenkinsfile @@ -19,15 +19,15 @@ pipeline { script { dir('project2') { sh "docker rm -f quotes-worker || true" - try { - // 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 cp quotes-worker:/app/quote.txt ." - } catch (e) { - echo "⚠️ Eroare la execuție: ${e.message}" - } finally { - sh "docker rm -f quotes-worker || true" - } + // Rulăm și afișăm log-urile containerului + 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 ." + + // DEBUG: Vedem ce e în fișier direct în Jenkins + echo "Conținut fișier extras:" + sh "cat quote.txt" } } }