Files
it_school/project2/famousquotes.py
Ionel Andrei Cataon 84fe05d110 p2
2026-02-12 17:11:59 +02:00

22 lines
751 B
Python

import requests
def get_quote():
try:
# Schimbăm la Quotable pentru a primi autorul
response = requests.get("https://api.quotable.io/random", timeout=10)
response.raise_for_status()
data = response.json()
quote = data.get('content', 'No quote found')
author = data.get('author', 'Unknown')
# 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}")
except Exception as e:
with open("quote.txt", "w", encoding="utf-8") as f:
f.write(f"⚠️ Eroare la preluare: {str(e)}")
if __name__ == "__main__":
get_quote()