Files
it_school/project2/famousquotes.py
Ionel Andrei Cataon dbdcb575df p2
2026-02-12 17:07:52 +02:00

22 lines
762 B
Python

import requests
def get_quote():
try:
# Folosim API-ul Quotable pentru a primi și 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')
# Salvăm formatat pentru 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"⚠️ Nu am putut prelua citatul. Eroare: {str(e)}")
if __name__ == "__main__":
get_quote()