26 lines
736 B
Python
26 lines
736 B
Python
import logging
|
|
from decimal import Decimal
|
|
|
|
import requests
|
|
from constance import config
|
|
from django.core.cache import cache
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def update_currencies_to_euro(
|
|
currency: str, amount: str | float | int | Decimal
|
|
) -> float:
|
|
logger.warning("update_currencies_to_euro will be deprecated soon!")
|
|
rates = cache.get("rates", None)
|
|
|
|
if not rates:
|
|
response = requests.get(
|
|
f"https://rates.icoadm.in/api/v1/rates?key={config.EXCHANGE_RATE_API_KEY}"
|
|
)
|
|
rates = response.json().get("rates")
|
|
cache.set("rates", rates, 60 * 60 * 24)
|
|
|
|
usd_to_eur = rates.get("eur")
|
|
|
|
return float(amount) * float(rates.get(currency.lower(), 1)) / float(usd_to_eur)
|