From d7db6303d323604550ceaa3211d7491c05394acd Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Wed, 25 Oct 2023 10:34:08 +0100 Subject: [PATCH] improve Billa parsing --- .../extractors/BillaProductsExtractor.kt | 8 ++-- .../resources/extractors/billa/expected.json | 40 +++++++++++++++++ .../resources/extractors/billa/input.html | 44 +++++++++++++++++++ 3 files changed, 89 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/stefanbratanov/sofiasupermarketsapi/extractors/BillaProductsExtractor.kt b/src/main/kotlin/com/stefanbratanov/sofiasupermarketsapi/extractors/BillaProductsExtractor.kt index f4e66fd..9a5819e 100644 --- a/src/main/kotlin/com/stefanbratanov/sofiasupermarketsapi/extractors/BillaProductsExtractor.kt +++ b/src/main/kotlin/com/stefanbratanov/sofiasupermarketsapi/extractors/BillaProductsExtractor.kt @@ -37,9 +37,11 @@ class BillaProductsExtractor : UrlProductsExtractor { "\\*+".toRegex(IGNORE_CASE), "Специфика\\s*:.*$".toRegex(IGNORE_CASE), "Супер цена".toRegex(IGNORE_CASE), - "МУЛТИ ПАК \\d+\\+\\d+".toRegex(IGNORE_CASE), - "Цена\\s+за\\s+\\d+\\s*бр\\.\\s*((без|с)\\s+отстъпка)?\\s*(\\d|\\.)+\\s*лв\\." - .toRegex(IGNORE_CASE) + "(?<=МУЛТИ ПАК.+)\\d+(х|x)".toRegex(IGNORE_CASE), + "МУЛТИ ПАК (\\d+\\+\\d+)?".toRegex(IGNORE_CASE), + "(\\d+(х|x)\\s*)?Цена\\s+за\\s+\\d+\\s*бр\\.\\s*((без|с)\\s+отстъпка)?\\s*(\\d|\\.|,)+\\s*лв\\.".toRegex( + IGNORE_CASE + ) ) private val regexesToDeleteBilla = diff --git a/src/test/resources/extractors/billa/expected.json b/src/test/resources/extractors/billa/expected.json index 5f75921..16be90a 100644 --- a/src/test/resources/extractors/billa/expected.json +++ b/src/test/resources/extractors/billa/expected.json @@ -1948,5 +1948,45 @@ "picUrl": null, "validFrom": "2021-03-18", "validUntil": "2021-03-24" + }, + { + "name": "Бира Tuborg кен", + "quantity": "0.5л", + "price": 1.33, + "oldPrice": 2.19, + "category": null, + "picUrl": null, + "validFrom": "2021-03-18", + "validUntil": "2021-03-24" + }, + { + "name": "Вино Montado", + "quantity": "0.75л", + "price": 7.99, + "oldPrice": 10.99, + "category": null, + "picUrl": null, + "validFrom": "2021-03-18", + "validUntil": "2021-03-24" + }, + { + "name": "Уиски Johnnie Walker Red Label", + "quantity": "0.7л", + "price": 18.99, + "oldPrice": 28.99, + "category": null, + "picUrl": null, + "validFrom": "2021-03-18", + "validUntil": "2021-03-24" + }, + { + "name": "Бира Starobrno кен", + "quantity": "0.5л", + "price": 1.225, + "oldPrice": 2.45, + "category": null, + "picUrl": null, + "validFrom": "2021-03-18", + "validUntil": "2021-03-24" } ] \ No newline at end of file diff --git a/src/test/resources/extractors/billa/input.html b/src/test/resources/extractors/billa/input.html index 982d38d..1a5a067 100644 --- a/src/test/resources/extractors/billa/input.html +++ b/src/test/resources/extractors/billa/input.html @@ -3695,6 +3695,50 @@
13.99лв.
+
+
МУЛТИ ПАК Бира Tuborg кен 12х0.5л Цена за 1 бр. 2,19 лв. + Цена за 12 бр. без отстъпка 26,28 лв.
+
СТАРА
ЦЕНА
+
+ 2.19 лв.
+
НОВА
ЦЕНА
+
- -39%
+
+ 1.33лв.
+
+
+
МУЛТИ ПАК Вино Montado 2x0.75л Цена за 1 бр. 10,99 лв. + Цена за 2 бр. без отстъпка 21,98 лв.
+
СТАРА
ЦЕНА
+
+ 10.99 лв.
+
НОВА
ЦЕНА
+
- -27%
+
+ 7.99лв.
+
+
+
МУЛТИ ПАК 1+1 Уиски Johnnie Walker Red Label 2x0.7л Цена за 1 бр. 28,99 лв. + Цена за 2 бр. без отстъпка 57,98 лв.
+
СТАРА
ЦЕНА
+
+ 28.99 лв.
+
НОВА
ЦЕНА
+
- -34%
+
+ 18.99лв.
+
+
+
МУЛТИ ПАК 1+1 Бира Starobrno кен 0.5л Цена за 1 бр. 2,45 лв. + Цена за 2 бр. без отстъпка 4,90 лв.
+
СТАРА
ЦЕНА
+
+ 2.45 лв.
+
НОВА
ЦЕНА
+
- -50%
+
+ 1.225лв.
+