Files
it_school/project2/famousquotes.py
Ionel Andrei Cataon 2e1da76f1f p2
2026-02-12 17:13:45 +02:00

28 lines
835 B
Python

import requests
import json
def get_quote():
url = "https://api.quotable.io/random"
try:
print(f"Connecting to {url}...")
response = requests.get(url, timeout=15)
response.raise_for_status()
data = response.json()
content = data.get('content', 'No content')
author = data.get('author', 'Unknown Author')
output = f"📜 *\"{content}\"*\n\n✍️ **Autor:** {author}"
with open("quote.txt", "w", encoding="utf-8") as f:
f.write(output)
print("Success: Quote and Author saved.")
except Exception as e:
error_msg = f"⚠️ Eroare API: {str(e)}"
print(error_msg)
with open("quote.txt", "w", encoding="utf-8") as f:
f.write(error_msg)
if __name__ == "__main__":
get_quote()