fix pre-commit
Some checks failed
CI/CD Pipeline / Telegram Notify Success (push) Has been cancelled
CI/CD Pipeline / Run Tests (push) Has been cancelled
CI/CD Pipeline / Code Quality Checks (push) Has been cancelled
CI/CD Pipeline / Code Quality Checks (pull_request) Successful in 1m42s
CI/CD Pipeline / Run Tests (pull_request) Successful in 2m25s
CI/CD Pipeline / Telegram Notify Success (pull_request) Successful in 1m34s

This commit is contained in:
2026-03-17 13:55:34 +01:00
parent 3d298ce352
commit 25176f31b4
31 changed files with 653 additions and 553 deletions

View File

@@ -21,8 +21,7 @@ DEFAULT_HOST = "minpromtorg.gov.ru"
DEFAULT_API_PATH = "/api/kss-document-preview"
DEFAULT_DOC_TYPE = "668d4f2a-966a-4b65-9fb9-2f1ad19a3d1f"
DEFAULT_QUERY = (
"Реестр промышленной продукции, произведенной на территории "
"Российской Федерации"
"Реестр промышленной продукции, произведенной на территории " "Российской Федерации"
)
DATE_PATTERN = re.compile(r"(\d{8})")
@@ -126,8 +125,7 @@ class IndustrialProductsClient:
adapter=self.http_adapter,
headers={
"User-Agent": (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"Chrome/120.0.0.0"
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) " "Chrome/120.0.0.0"
),
"Accept": "application/json",
},
@@ -225,7 +223,6 @@ class IndustrialProductsClient:
return products
def _detect_headers(self, worksheet) -> tuple[int, dict[str, int]]:
best_row = 1
best_map: dict[str, int] = {}
for row_index in range(1, min(worksheet.max_row, 10) + 1):
@@ -238,7 +235,6 @@ class IndustrialProductsClient:
)
header_map = self._build_header_map(row)
if len(header_map) > len(best_map):
best_row = row_index
best_map = header_map
if REQUIRED_HEADERS.issubset(header_map):
@@ -291,7 +287,9 @@ class IndustrialProductsClient:
if not any(product.__dict__.values()):
return None
if not product.registry_number or not product.product_name:
logger.warning("Skipping product row without registry number or name: %s", row)
logger.warning(
"Skipping product row without registry number or name: %s", row
)
return None
return product

View File

@@ -25,7 +25,6 @@ from django.http import Http404
from django.utils import timezone
from rest_framework.exceptions import ValidationError
SUCCESSFUL_LOAD_STATUSES = {"success", "skipped"}
ACTIVE_JOB_STATUSES = [JobStatus.PENDING, JobStatus.STARTED, JobStatus.RETRY]
@@ -104,9 +103,7 @@ SOURCE_CARD_DEFINITIONS: tuple[SourceCardDefinition, ...] = (
SourceItemDefinition(
code="procurements",
title="Единая информационная система закупок",
description=(
"Закупки и связанные данные из ЕИС по 44-ФЗ и 223-ФЗ."
),
description=("Закупки и связанные данные из ЕИС по 44-ФЗ и 223-ФЗ."),
parser_source=ParserLoadLog.Source.PROCUREMENTS,
),
),
@@ -215,7 +212,9 @@ class SourceCardService:
cards,
key=lambda item: (
item["last_updated_at"] is None,
-(item["last_updated_at"].timestamp()) if item["last_updated_at"] else 0,
-(item["last_updated_at"].timestamp())
if item["last_updated_at"]
else 0,
item["title"],
),
)
@@ -243,9 +242,13 @@ class SourceCardService:
@classmethod
def get_card(cls, slug: str) -> dict[str, Any]:
definition = cls.get_definition(slug)
source_items = [cls._build_source_item(item) for item in definition.source_items]
source_items = [
cls._build_source_item(item) for item in definition.source_items
]
records_count = sum(item["records_count"] for item in source_items)
organizations_count = cls._get_card_organizations_count(definition, source_items)
organizations_count = cls._get_card_organizations_count(
definition, source_items
)
latest_success_load = cls._get_latest_load(
definition,
@@ -311,7 +314,9 @@ class SourceCardService:
) -> dict[str, Any]:
definition = cls.get_definition(slug)
params = cls._validate_refresh_params(definition, params or {})
tasks = cls._launch_refresh(definition, requested_by_id=requested_by_id, params=params)
tasks = cls._launch_refresh(
definition, requested_by_id=requested_by_id, params=params
)
return {
"source_card": definition.slug,
@@ -339,8 +344,7 @@ class SourceCardService:
raise ValidationError(
{
"params": (
"Неизвестные параметры обновления: "
+ ", ".join(unknown_params)
"Неизвестные параметры обновления: " + ", ".join(unknown_params)
)
}
)
@@ -532,7 +536,9 @@ class SourceCardService:
"records_count": records_count,
"organizations_count": organizations_count,
"last_updated_at": (
latest_success_load.updated_at if latest_success_load else last_updated_at
latest_success_load.updated_at
if latest_success_load
else last_updated_at
),
"latest_load": cls._serialize_load_log(latest_load),
"latest_success_load": cls._serialize_load_log(latest_success_load),
@@ -571,7 +577,12 @@ class SourceCardService:
.count()
)
if item_code == "manufactures":
return ManufacturerRecord.objects.exclude(inn="").values("inn").distinct().count()
return (
ManufacturerRecord.objects.exclude(inn="")
.values("inn")
.distinct()
.count()
)
if item_code == "industrial_products":
return (
IndustrialProductRecord.objects.exclude(inn="")
@@ -580,7 +591,12 @@ class SourceCardService:
.count()
)
if item_code == "inspections":
return InspectionRecord.objects.exclude(inn="").values("inn").distinct().count()
return (
InspectionRecord.objects.exclude(inn="")
.values("inn")
.distinct()
.count()
)
if item_code == "procurements":
return (
ProcurementRecord.objects.exclude(customer_inn="")
@@ -677,14 +693,15 @@ class SourceCardService:
return queryset.order_by("-updated_at", "-created_at").first()
@classmethod
def _get_active_tasks(cls, definition: SourceCardDefinition) -> list[dict[str, Any]]:
def _get_active_tasks(
cls, definition: SourceCardDefinition
) -> list[dict[str, Any]]:
queryset = BackgroundJobService.get_queryset().filter(
task_name__in=definition.task_names,
status__in=ACTIVE_JOB_STATUSES,
)
return [
cls._serialize_job(job)
for job in queryset.order_by("-created_at")[:10]
cls._serialize_job(job) for job in queryset.order_by("-created_at")[:10]
]
@classmethod
@@ -757,7 +774,9 @@ class SourceCardService:
}
@classmethod
def _serialize_load_log(cls, load_log: ParserLoadLog | None) -> dict[str, Any] | None:
def _serialize_load_log(
cls, load_log: ParserLoadLog | None
) -> dict[str, Any] | None:
if load_log is None:
return None
return {