Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ on:
branches: ["main", "master"]
pull_request:

permissions:
contents: read

jobs:
build:
verify:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -19,10 +22,13 @@ jobs:
cache: npm

- name: Install dependencies
run: npm install
run: npm ci

- name: Type check
run: npm run check

- name: Run tests
run: npm test

- name: Build
run: npm run build
19 changes: 19 additions & 0 deletions .github/workflows/production-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Production Deploy

on:
push:
branches: ["main", "master"]
workflow_dispatch:

permissions:
contents: read

jobs:
deploy:
uses: nppweb/infra/.github/workflows/deploy.yml@main
with:
repo_name: scrape-helper
branch: ${{ github.ref_name }}
target_sha: ${{ github.sha }}
auto_rollback: true
secrets: inherit
18 changes: 14 additions & 4 deletions src/sources/eis/eis-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function mapEisNoticeToCollectedRecord(input: {
sourceName,
sourceType
};
const targetStationName = extractTargetStationName(notice, matchedQuery);
const targetStationName = extractTargetStationName(notice, sourceType, matchedQuery);

return {
url: notice.externalUrl,
Expand Down Expand Up @@ -73,13 +73,23 @@ export function mapEisNoticeToCollectedRecord(input: {

function extractTargetStationName(
notice: Pick<EisParsedNotice, "title" | "description" | "customerName" | "supplierName">,
sourceType: "procurement" | "contract",
matchedQuery?: string
): string | undefined {
return resolveNppStationNameFromText([
const directMatch = resolveNppStationNameFromText([
notice.title,
notice.description,
notice.customerName,
notice.supplierName,
matchedQuery
notice.supplierName
]);

if (directMatch) {
return directMatch;
}

if (sourceType === "contract") {
return resolveNppStationNameFromText([matchedQuery]);
}

return undefined;
}
57 changes: 57 additions & 0 deletions src/sources/eis/eis-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,61 @@ describe("eis-parser", () => {
supplierName: undefined
});
});

it("drops boilerplate title when parser lands on EIS documents page or popup-like shell", () => {
const html = `
<html>
<head>
<title>
Поделитесь мнением о качестве работы единой информационной системы
Перейти к опросу Система торгов Сбербанк-АСТ SBERBANK-AST.RU
Единая электронная торговая площадка ROSELTORG.RU
Техническая поддержка Ваши идеи по улучшению сайта
</title>
</head>
<body>
<h1>
Поделитесь мнением о качестве работы единой информационной системы
Перейти к опросу Система торгов Сбербанк-АСТ SBERBANK-AST.RU
Единая электронная торговая площадка ROSELTORG.RU
Техническая поддержка Ваши идеи по улучшению сайта
</h1>
</body>
</html>
`;

const notice = parseEisNoticePage(
html,
"https://zakupki.gov.ru/epz/order/notice/notice223/documents.html?regNumber=32615886957"
);

expect(notice.externalId).toBe("32615886957");
expect(notice.title).toBeUndefined();
expect(notice.description).toBeUndefined();
expect(notice.customerName).toBeUndefined();
});

it("prefers common-info pages over documents pages for the same notice", () => {
const html = `
<html>
<body>
<a href="/epz/order/notice/notice223/documents.html?regNumber=32615886957">Документы</a>
<a href="/epz/order/notice/notice223/common-info.html?regNumber=32615886957">Карточка</a>
</body>
</html>
`;

const results = parseEisSearchResults(html, {
baseUrl: "https://zakupki.gov.ru",
maxItems: 10
});

expect(results).toEqual([
{
externalId: "32615886957",
detailUrl: "https://zakupki.gov.ru/epz/order/notice/notice223/common-info.html?regNumber=32615886957",
title: "Карточка"
}
]);
});
});
50 changes: 36 additions & 14 deletions src/sources/eis/eis-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,18 @@ export function parseEisNoticePage(
readPageTitle($)
].map(normalizeExternalIdCandidate).find(Boolean) ?? "unknown";

const title =
const title = sanitizeNoticeTitle(
findFirstValue($, TITLE_LABELS, structuredValues) ??
readPrimaryHeading($) ??
findMetaContent($, "og:title") ??
findMetaContent($, "twitter:title");
readPrimaryHeading($) ??
findMetaContent($, "og:title") ??
findMetaContent($, "twitter:title")
);

const description =
const description = sanitizeNoticeDescription(
findFirstValue($, DESCRIPTION_LABELS, structuredValues) ??
findMetaContent($, "description") ??
undefined;
findMetaContent($, "description") ??
undefined
);

const customerName = sanitizePartyName(findFirstValue($, CUSTOMER_LABELS, structuredValues));
const supplierName = sanitizePartyName(findFirstValue($, SUPPLIER_LABELS, structuredValues));
Expand Down Expand Up @@ -315,12 +317,12 @@ function readPrimaryHeading($: CheerioAPI): string | undefined {
.first()
.text();
const heading = preferredHeading || $("h1, h2").first().text();
return cleanText(heading) || undefined;
return sanitizeNoticeTitle(heading);
}

function readPageTitle($: CheerioAPI): string | undefined {
const title = $("title").first().text();
return cleanText(title) || undefined;
return sanitizeNoticeTitle(title);
}

function findMetaContent($: CheerioAPI, name: string): string | undefined {
Expand Down Expand Up @@ -398,15 +400,19 @@ function isLikelyEisNoticeUrl(url: string, patterns?: string[]): boolean {

function getDetailUrlPriority(url: string): number {
if (url.includes("/view/common-info.html")) {
return 3;
return 5;
}

if (url.includes("common-info.html") || url.includes("contract-info.html")) {
return 4;
}

if (url.includes("common-info.html")) {
return 2;
if (url.includes("/documents.html")) {
return -2;
}

if (url.includes("/printForm/")) {
return 0;
return -3;
}

return 1;
Expand Down Expand Up @@ -512,7 +518,22 @@ function sanitizeRegion(value: string | undefined): string | undefined {
return cleaned;
}

function sanitizeNoticeTitle(value: string | undefined): string | undefined {
return sanitizeBoilerplateText(value, { maxLength: 400 });
}

function sanitizeNoticeDescription(value: string | undefined): string | undefined {
return sanitizeBoilerplateText(value, { maxLength: 4_000 });
}

function sanitizePartyName(value: string | undefined): string | undefined {
return sanitizeBoilerplateText(value, { maxLength: 220 });
}

function sanitizeBoilerplateText(
value: string | undefined,
options?: { maxLength?: number }
): string | undefined {
const cleaned = cleanText(value);

if (!cleaned) {
Expand All @@ -524,9 +545,10 @@ function sanitizePartyName(value: string | undefined): string | undefined {
const hasBoilerplateMarker = EIS_BOILERPLATE_MARKERS.some((marker) => normalized.includes(marker));
const hasPlatformNoise =
EIS_PLATFORM_DOMAIN_MARKERS.filter((marker) => normalized.includes(marker)).length >= 2;
const maxLength = options?.maxLength ?? 220;

if (
cleaned.length > 220 ||
cleaned.length > maxLength ||
urlMatches.length >= 3 ||
hasBoilerplateMarker ||
hasPlatformNoise ||
Expand Down
9 changes: 8 additions & 1 deletion src/sources/eis/eis-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,14 @@ function isRelevantNppItem(
return true;
}

if (resolveNppStationNameFromText([notice.title, notice.description, options?.matchedQuery])) {
if (
resolveNppStationNameFromText([
notice.title,
notice.description,
notice.customerName,
notice.supplierName
])
) {
return true;
}

Expand Down
Loading