Spaces:
Runtime error
Runtime error
File size: 706 Bytes
1f6c124 20c801a 1f6c124 20c801a 1f6c124 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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")
|