diff options
| author | unwox <me@unwox.com> | 2025-04-08 21:41:52 +0600 |
|---|---|---|
| committer | unwox <me@unwox.com> | 2025-04-08 21:41:52 +0600 |
| commit | 7f202b1a0d05f9e3bc3e3cec3d354b68454b99bd (patch) | |
| tree | 4746d3f3d8e4a938195f1b40514f8e3cf545985d | |
| parent | a7ec526534548f42d452e83c6c573202703fd932 (diff) | |
artoftea: finally fix the prices! [2]
| -rw-r--r-- | parser/artoftea.fnl | 26 | ||||
| -rw-r--r-- | parser/parser.fnl | 6 |
2 files changed, 19 insertions, 13 deletions
diff --git a/parser/artoftea.fnl b/parser/artoftea.fnl index 386dc77..1421a86 100644 --- a/parser/artoftea.fnl +++ b/parser/artoftea.fnl @@ -21,26 +21,30 @@ (parser.anywhere (parser.tag :a {:class "product-thumb__name" :href "*"} (peg.Cg (parser.till "</a>") :title))) - (+ - (* - (parser.anywhere + (parser.anywhere + (+ + (* (parser.tag :option {:data-price-prefix "*" - :data-price (peg.Cg (parser.till "\"") :price) + :data-price (peg.Cg (parser.till "\"") :amount) :value "*" :selected "selected"} - (peg.Cg (parser.till "</option>") :weight))) - (parser.anywhere - (parser.tag :span {:data-price "*" :class "*"} + (peg.Cg (parser.till "</option>") :weight)) + (parser.anywhere + (parser.tag :span {:data-price (peg.Cg (parser.till "\"") :price) + :class "*"} + (parser.till "</span>")))) + (parser.tag :span {:data-price (peg.Cg (parser.till "\"") :price) + :class "*"} (parser.till "</span>")))) - (parser.anywhere - (parser.tag :span {:data-price "*" :class "*"} - (peg.Cg (parser.till "</span>") :price)))) (parser.anywhere (parser.tag :span {} "В корзину")))) (fn normalize [product] (local year (parser.guess-year product.title)) (local weight (or (parser.guess-weight product.weight ["г"]) (parser.guess-weight product.title))) - (local price (number.string->number product.price)) + (local amount (if product.amount + (number.string->number product.amount) + 1)) + (local price (* (number.string->number product.price) amount)) {:site "artoftea" :title product.title diff --git a/parser/parser.fnl b/parser/parser.fnl index 15d9cd4..41b9112 100644 --- a/parser/parser.fnl +++ b/parser/parser.fnl @@ -158,7 +158,7 @@ (let [peg (peg.Ct (anywhere (* (+ (* (peg.C pegs.number) - (peg.S "xXхХ") + (+ (peg.P "x") "X" "х" "Х") (peg.C pegs.number)) (peg.C pegs.number)) (maybe (+ (peg.P " ") " ")) @@ -181,13 +181,15 @@ (fn test-guess-weight [] (assert (= nil (guess-weight "за 1")) "1") (assert (= 120 (guess-weight "6x20гр")) "2") - (assert (= 1260 (guess-weight "за 6x210гр")) "3") + (assert (= 140 (guess-weight "Знакомство с китайским чаем, 7х20 гр.")) "3") (assert (= 357 (guess-weight "за 1 шт 357 гр")) "4") (assert (= 1 (guess-weight "1гр")) "5") (assert (= 150 (guess-weight "150 гр")) "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 |
