import requests

def get_quote():
    # API alternativ foarte stabil
    url = "http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en"
    
    try:
        print(f"Obținem citat real de la {url}...")
        response = requests.get(url, timeout=10)
        response.raise_for_status()
        data = response.json()
        
        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:
        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()