diff options
| -rw-r--r-- | bin/fetch.fnl | 7 | ||||
| -rw-r--r-- | bin/serve.fnl | 4 | ||||
| -rw-r--r-- | parser/yoceramics.fnl | 61 | ||||
| -rw-r--r-- | static/yoceramics.webp | bin | 0 -> 4346 bytes |
4 files changed, 67 insertions, 5 deletions
diff --git a/bin/fetch.fnl b/bin/fetch.fnl index 434e33a..d3bbef9 100644 --- a/bin/fetch.fnl +++ b/bin/fetch.fnl @@ -19,6 +19,7 @@ (local ozchai (require :parser.ozchai)) (local suhexuan (require :parser.suhexuan)) (local tea108 (require :parser.tea108)) +(local yoceramics (require :parser.yoceramics)) (local teaworkshop (require :parser.teaworkshop)) (when _G.unpack @@ -167,9 +168,9 @@ FROM products;" [])) (must (luna.db.commit tx))) - (each [_ parser (pairs [daochai gorkovchay moychay ozchai suhexuan ipuer - artoftea clubcha chaekshop kolokolnikovchai tea108 - teaworkshop])] + (each [_ parser (pairs [yoceramics daochai gorkovchay moychay ozchai suhexuan + ipuer artoftea clubcha chaekshop kolokolnikovchai + tea108 teaworkshop])] (local products (parser.products)) (when (< 0 (# products)) ;; replace with with-tx diff --git a/bin/serve.fnl b/bin/serve.fnl index 8b43d81..8793537 100644 --- a/bin/serve.fnl +++ b/bin/serve.fnl @@ -464,8 +464,8 @@ [:option {:value val :selected (if (= form.site val) "selected" nil)} (. (require (.. "parser." val)) :title)]) - [:ozchai :suhexuan :ozchai :kolokolnikovchai :tea108 :ipuer - :clubcha :daochai :chaekshop :teaworkshop :artoftea + [:ozchai :suhexuan :ozchai :kolokolnikovchai :yoceramics :tea108 + :ipuer :clubcha :daochai :chaekshop :teaworkshop :artoftea :moychay :gorkovchay]))]] [:div {} [:select {:name "sort"} diff --git a/parser/yoceramics.fnl b/parser/yoceramics.fnl new file mode 100644 index 0000000..af0ec0a --- /dev/null +++ b/parser/yoceramics.fnl @@ -0,0 +1,61 @@ +(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://yoceramics.ru/product-category/" path + (if (= 1 page) "" (.. "/page/" page)) "/?per_page=36")) + +(local product-peg + (* + (parser.anywhere "class=\"product-image-link\"") + (parser.anywhere (* "src=\"" (peg.Cg (parser.till "\"") :image) "\"")) + (parser.anywhere + (parser.tag :h3 {:class "wd-entities-title"} + (parser.tag :a {:href (peg.Cg (parser.till "\"") :url)} + (peg.Cg (parser.till "</a>") :title)))) + (parser.anywhere + (parser.tag :span {:class "woocommerce-Price-amount amount"} + (parser.tag :bdi {} + (* + (peg.Cg (parser.till " ") :price) + (parser.till "</bdi>"))))) + (parser.anywhere + (parser.tag :div {:class "hover-content-inner wd-more-desc-inner"} + (* + (parser.maybe parser.pegs.spaces) + (peg.Cg (parser.till "</div>") :description)))) + (parser.anywhere (parser.tag :span {} "В корзину")))) + +(fn normalize [product] + {:site "yoceramics" + :title product.title + :url product.url + :description product.description + :image product.image + :year nil + :price (number.string->number product.price) + :weight nil + :volume (parser.guess-volume product.description) + :price-per nil}) + +(fn products [] + (fetcher.from-html + [{:path "gajvani" :tags ["Посуда" "Керамика" "Гайвань"]} + {:path "vazy" :tags ["Посуда" "Керамика" "Ваза"]} + {:path "kensuj" :tags ["Посуда" "Керамика" "Кенсуй"]} + {:path "pialy-i-chashi" :tags ["Посуда" "Керамика" "Пиала"]} + {:path "tyavany" :tags ["Посуда" "Керамика" "Тяван"]} + {:path "chajniki" :tags ["Посуда" "Керамика" "Чайник"]} + {:path "chahai" :tags ["Посуда" "Керамика" "Чахай"]} + {:path "chajnye-prudiki" :tags ["Посуда" "Керамика" "Чайный пруд"]} + {:path "chahe" :tags ["Посуда" "Керамика" "Чахэ"]}] + format-url + product-peg + normalize)) + +{:products products :title "yo_ceramics" :url "https://www.yoceramics.ru"} diff --git a/static/yoceramics.webp b/static/yoceramics.webp Binary files differnew file mode 100644 index 0000000..a0e6a70 --- /dev/null +++ b/static/yoceramics.webp |
