feat: add empty_weigh and full_weight fields for auto and mechanic rvalution models

This commit is contained in:
xoliqberdiyev
2026-05-06 15:12:46 +05:00
parent a17c2a52ce
commit 23b8c1450f
10 changed files with 123 additions and 79 deletions

View File

@@ -2,4 +2,5 @@ from .otp import * # noqa
from .sms import * # noqa
from .user import * # noqa
from .didox import * # noqa
from .tech_passport import * # noqa
from .tech_passport import * # noqa
from .currency import * # noqa

33
core/services/currency.py Normal file
View File

@@ -0,0 +1,33 @@
from datetime import date
import requests
import logging
logger = logging.getLogger(__name__)
class CurrencyService:
BASE_URL = "https://cbu.uz/oz/arkhiv-kursov-valyut/json"
CODES = ("USD", "EUR", "RUB")
TIMEOUT_SECONDS = 5
@classmethod
def get_rates(cls, target_date=None) -> dict:
if target_date is None:
target_date = date.today()
date_str = target_date.strftime("%Y-%m-%d")
rates = {}
for code in cls.CODES:
url = f"{cls.BASE_URL}/{code}/{date_str}/"
try:
response = requests.get(url, timeout=cls.TIMEOUT_SECONDS)
response.raise_for_status()
payload = response.json()
if isinstance(payload, list) and payload:
rate_value = payload[0].get("Rate")
if rate_value:
rates[code] = rate_value
except (requests.RequestException, ValueError) as e:
logger.exception(f"CBU API error for {code}: {e}")
return rates