summaryrefslogtreecommitdiff
path: root/parser
diff options
context:
space:
mode:
Diffstat (limited to 'parser')
-rw-r--r--parser/yoceramics.fnl61
1 files changed, 61 insertions, 0 deletions
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 "&nbsp;") :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"}