fix: exclude provider records from source exports
This commit is contained in:
@@ -43,6 +43,11 @@ DEFAULT_XLSX_DATA_ROWS_PER_FILE = 100_000
|
||||
DEFAULT_DOWNLOAD_TICKET_TTL_SECONDS = 5 * 60
|
||||
SOURCE_RECORD_EXPORT_TICKET_CACHE_PREFIX = "organizations:source-record-exports:ticket"
|
||||
SOURCE_RECORD_EXPORT_TICKET_PATTERN = re.compile(r"[A-Za-z0-9_-]{43}")
|
||||
EXCLUDED_EXPORT_PROVIDER_PATTERN = re.compile(
|
||||
r"(?<![A-Za-zА-Яа-яЁё0-9])(?:checko(?:\.ru)?|чекало|чекко|чеко)"
|
||||
r"(?![A-Za-zА-Яа-яЁё0-9])",
|
||||
flags=re.IGNORECASE,
|
||||
)
|
||||
|
||||
SOURCE_GROUP_EXPORT_FILE_STEMS: dict[str, str] = {
|
||||
SourceGroup.FINANCIAL_INDICATORS.value: "financial-indicators",
|
||||
@@ -56,7 +61,7 @@ SOURCE_GROUP_EXPORT_FILE_STEMS: dict[str, str] = {
|
||||
SourceGroup.VACANCIES.value: "labor-vacancies",
|
||||
}
|
||||
|
||||
ORGANIZATION_EXPORT_FIELDS = ["Наименование", "ИНН", "ОГРН", "КПП"]
|
||||
ORGANIZATION_EXPORT_FIELDS = ["Наименование", "ИНН", "ОГРН", "КПП", "ОКПО"]
|
||||
SOURCE_RECORD_EXPORT_FIELDS = [
|
||||
"uid",
|
||||
"source_group",
|
||||
@@ -530,6 +535,8 @@ def _spool_source_group_rows(
|
||||
source_group=source_group,
|
||||
include_financial_lines=include_financial_lines,
|
||||
):
|
||||
if _is_excluded_export_provider_record(record):
|
||||
continue
|
||||
row = _build_record_row(
|
||||
record,
|
||||
include_financial_lines=include_financial_lines,
|
||||
@@ -696,6 +703,7 @@ def _build_record_row(
|
||||
"ИНН": organization.inn,
|
||||
"ОГРН": organization.ogrn,
|
||||
"КПП": organization.kpp,
|
||||
"ОКПО": organization.okpo,
|
||||
"uid": str(record.uid),
|
||||
"source_group": record.extension.source_group,
|
||||
"source": record.source,
|
||||
@@ -724,6 +732,32 @@ def _build_record_row(
|
||||
return serialized_row
|
||||
|
||||
|
||||
def _is_excluded_export_provider_record(record: OrganizationSourceRecord) -> bool:
|
||||
"""Return whether a provider-backed record must stay out of public files."""
|
||||
values = (
|
||||
record.source,
|
||||
record.external_id,
|
||||
record.title,
|
||||
record.url,
|
||||
record.payload,
|
||||
)
|
||||
return any(_contains_excluded_export_provider(value) for value in values)
|
||||
|
||||
|
||||
def _contains_excluded_export_provider(value: object) -> bool:
|
||||
if isinstance(value, str):
|
||||
return EXCLUDED_EXPORT_PROVIDER_PATTERN.search(value) is not None
|
||||
if isinstance(value, dict):
|
||||
return any(
|
||||
_contains_excluded_export_provider(key)
|
||||
or _contains_excluded_export_provider(item)
|
||||
for key, item in value.items()
|
||||
)
|
||||
if isinstance(value, list | tuple):
|
||||
return any(_contains_excluded_export_provider(item) for item in value)
|
||||
return False
|
||||
|
||||
|
||||
def _flatten_payload(value: Any, *, prefix: str = "payload") -> dict[str, Any]:
|
||||
if not isinstance(value, dict):
|
||||
return {prefix: value} if value not in (None, "") else {}
|
||||
|
||||
Reference in New Issue
Block a user