- contract PDF: map report/customer/owner/contract from AutoEvaluationModel fields, accept inspection via POST serializer, fetch CBU.uz currency rates - MechanicAutoEvaluation: add distance_covered, object_owner_residence and car_position/body_type/fuel_type/state_car/assessment_task_type FKs; drop car_type and single tex_passport_file in favour of multi-file FK model Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
34 lines
998 B
Python
34 lines
998 B
Python
from datetime import date
|
|
|
|
import requests
|
|
|
|
CBU_URL = "https://cbu.uz/oz/arkhiv-kursov-valyut/json/{code}/{date}/"
|
|
TIMEOUT_SECONDS = 5
|
|
CURRENCY_CODES = ("USD", "EUR", "RUB")
|
|
|
|
|
|
def fetch_rates(target_date):
|
|
"""CBU.uz dan berilgan sanaga oid USD, EUR, RUB kurslarini olish.
|
|
|
|
Tarmoq xatosi yoki notogri javob bolsa bosh dict qaytadi.
|
|
"""
|
|
if target_date is None:
|
|
target_date = date.today()
|
|
date_str = target_date.strftime("%Y-%m-%d")
|
|
rates = {}
|
|
for code in CURRENCY_CODES:
|
|
try:
|
|
resp = requests.get(
|
|
CBU_URL.format(code=code, date=date_str),
|
|
timeout=TIMEOUT_SECONDS,
|
|
)
|
|
resp.raise_for_status()
|
|
data = resp.json()
|
|
if isinstance(data, list) and data:
|
|
rate_value = data[0].get("Rate")
|
|
if rate_value:
|
|
rates[code] = rate_value
|
|
except (requests.RequestException, ValueError):
|
|
continue
|
|
return rates
|