[2
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
def get_quote():
|
||||
url = "https://api.quotable.io/random"
|
||||
# Folosim un endpoint de fallback care e foarte stabil
|
||||
url = "https://api.adviceslip.com/advice"
|
||||
try:
|
||||
print(f"Connecting to {url}...")
|
||||
response = requests.get(url, timeout=15)
|
||||
print(f"Încercăm conectarea la {url}...")
|
||||
response = requests.get(url, timeout=10)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
content = data.get('content', 'No content')
|
||||
author = data.get('author', 'Unknown Author')
|
||||
advice = data.get('slip', {}).get('advice', 'Fii bun cu cei din jur.')
|
||||
|
||||
output = f"📜 *\"{content}\"*\n\n✍️ **Autor:** {author}"
|
||||
# Deoarece AdviceSlip e anonim, punem noi un autor simbolic
|
||||
output = f"📜 *\"{advice}\"*\n\n✍️ **Autor:** AdviceSlip Bot"
|
||||
|
||||
with open("quote.txt", "w", encoding="utf-8") as f:
|
||||
f.write(output)
|
||||
print("Success: Quote and Author saved.")
|
||||
print("Succes: Sfatul a fost salvat.")
|
||||
|
||||
except Exception as e:
|
||||
error_msg = f"⚠️ Eroare API: {str(e)}"
|
||||
print(error_msg)
|
||||
fallback = "📜 *\"Eroarea de astăzi este lecția de mâine.\"*\n\n✍️ **Autor:** Jenkins Debugger"
|
||||
with open("quote.txt", "w", encoding="utf-8") as f:
|
||||
f.write(error_msg)
|
||||
f.write(fallback)
|
||||
print(f"Fallback activat din cauza: {str(e)}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
get_quote()
|
||||
Reference in New Issue
Block a user