summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/fetch.fnl3
-rw-r--r--bin/serve.fnl4
-rw-r--r--parser/chaibez.fnl114
-rw-r--r--static/chaibez.webpbin0 -> 7850 bytes
4 files changed, 118 insertions, 3 deletions
diff --git a/bin/fetch.fnl b/bin/fetch.fnl
index 794d147..dd7c6c4 100644
--- a/bin/fetch.fnl
+++ b/bin/fetch.fnl
@@ -10,6 +10,7 @@
(local artoftea (require :parser.artoftea))
(local batatcha (require :parser.batatcha))
+(local chaibez (require :parser.chaibez))
(local chaekshop (require :parser.chaekshop))
(local clubcha (require :parser.clubcha))
(local daochai (require :parser.daochai))
@@ -196,7 +197,7 @@
(each [_ parser (pairs [batatcha yoceramics daochai gorkovchay ozchai suhexuan
ipuer artoftea clubcha chaekshop kolokolnikovchai
- tea108 teaworkshop moychay])]
+ tea108 teaworkshop chaibez moychay])]
(local products (parser.products))
(when (< 0 (# products))
;; replace with with-tx
diff --git a/bin/serve.fnl b/bin/serve.fnl
index 0d742e3..b764338 100644
--- a/bin/serve.fnl
+++ b/bin/serve.fnl
@@ -469,8 +469,8 @@
:selected (if (= form.site val) "selected" nil)}
(. (require (.. "parser." val)) :title)])
[:suhexuan :ozchai :batatcha :kolokolnikovchai :yoceramics :tea108
- :ipuer :clubcha :daochai :chaekshop :teaworkshop :artoftea
- :moychay :gorkovchay]))]]
+ :ipuer :clubcha :daochai :chaekshop :teaworkshop :chaibez
+ :artoftea :moychay :gorkovchay]))]]
[:div {}
[:select {:name "sort"}
[:option {:value ""} "~ Порядок ~"]
diff --git a/parser/chaibez.fnl b/parser/chaibez.fnl
new file mode 100644
index 0000000..d42a4ae
--- /dev/null
+++ b/parser/chaibez.fnl
@@ -0,0 +1,114 @@
+(local peg
+ (if (pick-values 1 (pcall require :lpeg))
+ (require :lpeg)
+ (require :lpeglj)))
+(local parser (require :parser.parser))
+(local number (require :lib.number))
+(local fetcher (require :fetcher))
+
+(fn format-url [path page]
+ (.. "https://chaibez.ru/" path "/"
+ (if (< 1 page) (.. "?page=" page) "")))
+
+(local product-peg
+ (*
+ (parser.anywhere
+ (parser.tag :div {:class "image"}
+ (parser.tag :a {:href (peg.Cg (parser.till "\"") :url) :class "*"}
+ (*
+ (parser.anywhere (* "src=\"" (peg.Cg (parser.till "\"") :image) "\""))
+ (parser.till "</a>")))))
+ (parser.anywhere
+ (*
+ "<div class=\"caption\">"
+ parser.pegs.spaces
+ (parser.tag :h4 {}
+ (*
+ (parser.tag :a {:href (peg.Cg (parser.till "\"") :url)}
+ (peg.Cg (parser.till "</a>") :title))
+ (parser.till "</h4>")))))
+ ;; same engine as artoftea
+ (parser.anywhere
+ (+
+ (*
+ (+
+ ;; 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>"))))
+ ;; without options
+ (parser.tag :span {:data-price (peg.Cg (parser.till "\"") :price)
+ :class "*"}
+ (parser.till "</span>"))))
+ (parser.anywhere (parser.tag :span {:class "*"} "В корзину"))))
+
+(fn normalize [product]
+ (local year (parser.guess-year product.title))
+ (local weight (or (parser.guess-weight product.weight ["г"])
+ (parser.guess-weight product.title)))
+ (local amount (if product.amount
+ (number.string->number product.amount)
+ 1))
+ (local price (number.string->number product.price))
+ (local final-price (if (= product.prefix "*")
+ (* price amount)
+ (= product.prefix "=")
+ amount
+ price))
+
+ {:site "chaibez"
+ :title product.title
+ :url product.url
+ :description product.description
+ :image product.image
+ :year year
+ :price final-price
+ :weight weight
+ :volume (parser.guess-volume product.title)
+ :price-per (if (and final-price weight (< 0 weight))
+ (/ (math.ceil (* (/ final-price weight) 10)) 10)
+ nil)})
+
+ (fn products []
+ (fetcher.from-html
+ [{:path "red_tea" :tags ["Красный чай"]}
+ {:path "green_tea" :tags ["Зеленый чай"]}
+ {:path "puer/shu_puer" :tags ["Шу пуэр"]}
+ {:path "puer/rassypnoj-puer" :tags ["Шу пуэр"]}
+ {:path "puer/shen_puer" :tags ["Шен пуэр"]}
+ {:path "ulun/svetliy-ulun" :tags ["Улун"]}
+ {:path "ulun/temniy-ulun" :tags ["Улун" "Уишань"]}
+ {:path "ulun/ulun-guandun" :tags ["Улун" "Гуандун"]}
+ {:path "ulun/gaba" :tags ["Улун" "Габа"]}
+ {:path "ulun/taivan-ulun" :tags ["Улун" "Тайвань"]}
+ {:path "white_tea" :tags ["Белый чай"]}
+ {:path "yellow-tea" :tags ["Желтый чай"]}
+ {:path "xej-cha-chernyj-chaj" :tags ["Хэй ча"]}
+ {:path "posuda/gajvani" :tags ["Посуда" "Гайвань"]}
+ {:path "posuda/kolba-station" :tags ["Посуда" "Стекло"]}
+ {:path "posuda/chahai" :tags ["Посуда" "Чахай"]}
+ {:path "posuda/isinskie-chajniki" :tags ["Посуда" "Чайник" "Исин"]}
+ {:path "posuda/pials" :tags ["Посуда" "Пиала"]}
+ {:path "posuda/chajniki-s-knopkoi" :tags ["Посуда" "Типот"]}
+ {:path "aksessuary/chabani-chajnye-dosk" :tags ["Чабань"]}
+ {:path "aksessuary/figurki" :tags ["Фигурка"]}
+ {:path "aksessuary/instrumenty-kistochki-shhipcy-shilo" :tags ["Инструмент"]}
+ {:path "aksessuary/chaxe-sitechki" :tags ["Сито"]}
+ {:path "aksessuary/cases" :tags ["Чехол"]}
+ {:path "trav_tea" :tags ["Травяной чай"]}]
+ format-url
+ product-peg
+ normalize))
+
+{:products products :title "Чай без церемоний" :url "https://chaibez.ru"}
diff --git a/static/chaibez.webp b/static/chaibez.webp
new file mode 100644
index 0000000..b1b2426
--- /dev/null
+++ b/static/chaibez.webp
Binary files differ