28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
import requests
|
|
|
|
def get_quote():
|
|
# Folosim un endpoint de fallback care e foarte stabil
|
|
url = "https://api.adviceslip.com/advice"
|
|
try:
|
|
print(f"Încercăm conectarea la {url}...")
|
|
response = requests.get(url, timeout=10)
|
|
response.raise_for_status()
|
|
data = response.json()
|
|
|
|
advice = data.get('slip', {}).get('advice', 'Fii bun cu cei din jur.')
|
|
|
|
# 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("Succes: Sfatul a fost salvat.")
|
|
|
|
except Exception as e:
|
|
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(fallback)
|
|
print(f"Fallback activat din cauza: {str(e)}")
|
|
|
|
if __name__ == "__main__":
|
|
get_quote() |