p2
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
import requests
|
||||
|
||||
def get_quote():
|
||||
# Folosim un endpoint de fallback care e foarte stabil
|
||||
url = "https://api.adviceslip.com/advice"
|
||||
# API alternativ foarte stabil
|
||||
url = "http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en"
|
||||
|
||||
try:
|
||||
print(f"Încercăm conectarea la {url}...")
|
||||
print(f"Obținem citat real de 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.")
|
||||
text = data.get('quoteText', 'Keep pushing forward.')
|
||||
author = data.get('quoteAuthor', 'Unknown')
|
||||
if not author.strip(): author = "Anonim"
|
||||
|
||||
output = f"📜 *\"{text}\"*\n\n✍️ **Autor:** {author}"
|
||||
|
||||
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)}")
|
||||
print(f"API indisponibil ({e}). Folosim rezerva locală...")
|
||||
# Rezervă de calitate în caz de eroare rețea
|
||||
output = "📜 *\"Success is not final, failure is not fatal: it is the courage to continue that counts.\"*\n\n✍️ **Autor:** Winston Churchill"
|
||||
|
||||
with open("quote.txt", "w", encoding="utf-8") as f:
|
||||
f.write(output)
|
||||
|
||||
if __name__ == "__main__":
|
||||
get_quote()
|
||||
Reference in New Issue
Block a user