From 12bbb2650a1afb4afb9c1774b756e9c3826367b7 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Mon, 10 Feb 2020 16:15:09 -0500 Subject: importer fixes --- src/scraping/buxton/final/BuxtonImporter.ts | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'src/scraping') diff --git a/src/scraping/buxton/final/BuxtonImporter.ts b/src/scraping/buxton/final/BuxtonImporter.ts index 9da80e787..b8016be13 100644 --- a/src/scraping/buxton/final/BuxtonImporter.ts +++ b/src/scraping/buxton/final/BuxtonImporter.ts @@ -71,24 +71,6 @@ namespace Utilities { return { transformed: raw }; } - export function tryGetValidCapture(matches: RegExpExecArray | null, matchIndex: number): string | undefined { - let captured: string; - if (!matches || !(captured = matches[matchIndex])) { - return undefined; - } - const lower = captured.toLowerCase(); - if (/to come/.test(lower)) { - return undefined; - } - if (lower.includes("xxx")) { - return undefined; - } - if (!captured.toLowerCase().replace(/[….\s]+/g, "").length) { - return undefined; - } - return captured; - } - export function capitalize(word: string): string { const clean = word.trim(); if (!clean.length) { @@ -128,7 +110,7 @@ const RegexMap = new Map>([ exp: /Original Price \(USD\)\:\s+(\$[0-9]+\.[0-9]+|NFS)/, transformer: (raw: string) => { if (raw === "NFS") { - return { transformed: raw }; + return { transformed: -1 }; } return Utilities.numberValue(raw.slice(1)); } @@ -313,7 +295,7 @@ async function writeImages(zip: any): Promise { out.on("error", reject); }); } - imageUrls.push(`http://localhost:1050/files/images/buxton/${generatedFileName}`); + imageUrls.push(`/files/images/buxton/${generatedFileName}`); } return imageUrls; @@ -345,8 +327,8 @@ function analyze(fileName: string, { body, imageUrls, captions, hyperlinks }: Do const { exp, transformer, matchIndex, required } = RegexMap.get(key)!; const matches = exp.exec(body); - let captured = Utilities.tryGetValidCapture(matches, matchIndex ?? 1); - if (captured) { + let captured: string; + if (matches && (captured = matches[matchIndex ?? 1])) { captured = captured.replace(/\s{2,}/g, " "); if (transformer) { const { error, transformed } = transformer(captured); -- cgit v1.2.3-70-g09d2