Currency-Converter / frankfurter.py
bikas
Currency Converter
20c801a
raw
history blame contribute delete
706 Bytes
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")