Spaces:
Runtime error
Runtime error
import requests | |
BASE_URL = "https://api.frankfurter.app" | |
def get_latest_rate(from_currency, to_currency): | |
response = requests.get(f"{BASE_URL}/latest?from={from_currency}&to={to_currency}") | |
if response.status_code == 200: | |
data = response.json() | |
return data['rates'][to_currency] | |
else: | |
raise Exception("Failed to fetch the latest rate") | |
def get_historical_rate(from_currency, to_currency, date): | |
response = requests.get(f"{BASE_URL}/{date}?from={from_currency}&to={to_currency}") | |
if response.status_code == 200: | |
data = response.json() | |
return data['rates'][to_currency] | |
else: | |
raise Exception("Failed to fetch historical rate") | |