(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://artoftea.ru/" path (if (< 1 page) (.. "?page=" page) ""))) (local product-peg (* (parser.anywhere (parser.tag :div {:class "product-thumb__image"} (parser.tag :a {:href (peg.Cg (parser.till "\"") :url) :title "*"} (* (parser.anywhere (* "src=\"" (peg.Cg (parser.till "\"") :image) "\"")) (parser.till ""))))) (parser.anywhere (parser.tag :a {:class "product-thumb__name" :href "*"} (peg.Cg (parser.till "") :title))) (+ (* (parser.anywhere (parser.tag :option {:data-price-prefix "*" :data-price (peg.Cg (parser.till "\"") :price) :value "*" :selected "selected"} (peg.Cg (parser.till "") :weight))) (parser.anywhere (parser.tag :span {:data-price "*" :class "*"} (parser.till "")))) (parser.anywhere (parser.tag :span {:data-price "*" :class "*"} (peg.Cg (parser.till "") :price)))) (parser.anywhere (parser.tag :span {} "В корзину")))) (fn normalize [product] (local year (parser.guess-year product.title)) (local weight (or (parser.guess-weight product.weight ["г"]) (parser.guess-weight product.title))) (local price (number.string->number product.price)) {:site "artoftea" :title product.title :url product.url :description product.description :image product.image :year year :price price :weight weight :volume (parser.guess-volume product.title) :price-per (if (and price weight (< 0 weight)) (/ (math.ceil (* (/ price weight) 10)) 10) nil)}) (fn products [] (fetcher.from-html [{:path "redtea" :tags ["Красный чай"]} {:path "greentea" :tags ["Зеленый чай"]} {:path "puer/shu-puer" :tags ["Шу пуэр"]} {:path "puer/sheng-puer" :tags ["Шен пуэр"]} {:path "rassypnoi-puer"} {:path "oolong" :tags ["Улун"]} {:path "whitetea" :tags ["Белый чай"]} {:path "yellowtea" :tags ["Желтый чай"]} {:path "xej-cha-chernyj-chaj" :tags ["Хэй ча"]} {:path "posuda/gaiwans" :tags ["Посуда" "Гайвань"]} {:path "posuda/cups" :tags ["Посуда" "Пиала"]} {:path "posuda/chahai" :tags ["Посуда" "Чахай"]} {:path "posuda/chainiki-steklo-farfor" :tags ["Посуда" "Стекло"]} {:path "posuda/chainiki-isinskaya-glina" :tags ["Посуда" "Чайник" "Исин"]} {:path "posuda/chayniki-iz-keramiki-farfora" :tags ["Посуда" "Чайник" "Керамика"]} {:path "posuda/farfor-iz-tszindechzhen" :tags ["Посуда" "Цзиндэчжэнь"]} {:path "posuda/keramika-iz-tszyanshuy" :tags ["Посуда" "Чайник" "Цзяньшуй"]} {:path "posuda/keramika-iz-chaochzhou" :tags ["Посуда" "Чайник" "Чаочжоу"]} {:path "posuda/posuda-iz-tsinchzhou" :tags ["Посуда" "Чайник" "Гуанси"]} {:path "posuda/termosy-zavarochnyye-butylki" :tags ["Посуда" "Термос"]} {:path "posuda/sama-kamjove" :tags ["Посуда" "Типот"]} {:path "posuda/steklo" :tags ["Посуда" "Стекло"]} {:path "posuda/nabory" :tags ["Посуда" "Набор"]} {:path "posuda/ekskljuzivnaja-posuda" :tags ["Посуда" "Набор"]} {:path "accesories/chaban" :tags ["Чабань"]} {:path "accesories/instrumenty" :tags ["Инструмент"]} {:path "accesories/tea-toys" :tags ["Фигурка"]} {:path "accesories/tea-toys" :tags ["Фигурка"]} {:path "accesories/chahe-strainers" :tags ["Сито"]} {:path "accesories/miscellaneous" :tags ["Аксессуар"]} {:path "accesories/firmenny-stil" :tags ["Мерч"]} {:path "accesories/stikery" :tags ["Мерч"]} {:path "upakovka" :tags ["Упаковка"]} {:path "eksklyuzivny-chay"} {:path "taiwan-tea" :tags ["Тайвань"]}] format-url product-peg normalize)) {:products products :title "Art of tea" :url "https://artoftea.ru"}