From 6f832146573fd98f5002ffb261f4a245ee27d643 Mon Sep 17 00:00:00 2001 From: unwox Date: Mon, 5 May 2025 23:37:44 +0600 Subject: artoftea: finally fix the prices >:( [3] --- parser/artoftea.fnl | 36 +++++++++++++++++++++++++----------- parser/parser.fnl | 3 --- 2 files changed, 25 insertions(+), 14 deletions(-) (limited to 'parser') diff --git a/parser/artoftea.fnl b/parser/artoftea.fnl index 1421a86..c8f25ee 100644 --- a/parser/artoftea.fnl +++ b/parser/artoftea.fnl @@ -24,17 +24,26 @@ (parser.anywhere (+ (* - (parser.tag :option {:data-price-prefix "*" - :data-price (peg.Cg (parser.till "\"") :amount) - :value "*" :selected "selected"} - (peg.Cg (parser.till "") :weight)) + (+ + ;; without discount + (parser.tag :option {:data-price-prefix (peg.Cg (parser.till "\"") :prefix) + :data-price (peg.Cg (parser.till "\"") :amount) + :value "*" :selected "selected"} + (peg.Cg (parser.till "") :weight)) + ;; with discount + (parser.tag :option {:data-price-prefix (peg.Cg (parser.till "\"") :prefix) + :data-price "*" + :data-special (peg.Cg (parser.till "\"") :amount) + :value "*" :selected "selected"} + (peg.Cg (parser.till "") :weight))) (parser.anywhere (parser.tag :span {:data-price (peg.Cg (parser.till "\"") :price) :class "*"} (parser.till "")))) - (parser.tag :span {:data-price (peg.Cg (parser.till "\"") :price) - :class "*"} - (parser.till "")))) + ;; without options + (parser.tag :span {:data-price (peg.Cg (parser.till "\"") :price) + :class "*"} + (parser.till "")))) (parser.anywhere (parser.tag :span {} "В корзину")))) (fn normalize [product] @@ -44,7 +53,12 @@ (local amount (if product.amount (number.string->number product.amount) 1)) - (local price (* (number.string->number product.price) amount)) + (local price (number.string->number product.price)) + (local final-price (if (= product.prefix "*") + (* price amount) + (= product.prefix "=") + amount + price)) {:site "artoftea" :title product.title @@ -52,11 +66,11 @@ :description product.description :image product.image :year year - :price price + :price final-price :weight weight :volume (parser.guess-volume product.title) - :price-per (if (and price weight (< 0 weight)) - (/ (math.ceil (* (/ price weight) 10)) 10) + :price-per (if (and final-price weight (< 0 weight)) + (/ (math.ceil (* (/ final-price weight) 10)) 10) nil)}) (fn products [] diff --git a/parser/parser.fnl b/parser/parser.fnl index 41b9112..b15276f 100644 --- a/parser/parser.fnl +++ b/parser/parser.fnl @@ -188,8 +188,6 @@ (assert (= 1000 (guess-weight "1кг")) "7") (assert (= 150 (guess-weight "150 г" ["г"])) "8")) -(test-guess-weight) - (fn guess-volume [text] (if text (let [peg (peg.Ct @@ -209,7 +207,6 @@ (assert (= nil (guess-volume "Сервиз Хуа Хэ Няо"))) (assert (= 255 (guess-volume "Бутылка для чая «Походная» 255 мл"))) (assert (= 255 (guess-volume "Бутылка для чая «Походная» 255 мл")))) -(test-guess-volume) {: match-many : tag -- cgit v1.2.3