diff options
Diffstat (limited to 'parser/artoftea.fnl')
| -rw-r--r-- | parser/artoftea.fnl | 36 |
1 files changed, 25 insertions, 11 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 [] |
