summaryrefslogtreecommitdiff
path: root/parser
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2025-05-05 23:37:44 +0600
committerunwox <me@unwox.com>2025-05-05 23:37:44 +0600
commit6f832146573fd98f5002ffb261f4a245ee27d643 (patch)
tree3910d15bf726b6413aaaa732d8ab6feb54084f9d /parser
parente29deb3f296b19ac7e7d6bd5facb4b0b53b3f50a (diff)
artoftea: finally fix the prices >:( [3]
Diffstat (limited to 'parser')
-rw-r--r--parser/artoftea.fnl36
-rw-r--r--parser/parser.fnl3
2 files changed, 25 insertions, 14 deletions
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 "</option>") :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 "</option>") :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 "</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>"))))
+ ;; without options
+ (parser.tag :span {:data-price (peg.Cg (parser.till "\"") :price)
+ :class "*"}
+ (parser.till "</span>"))))
(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&nbsp;мл"))))
-(test-guess-volume)
{: match-many
: tag