(import-macros {: map} :lib.macro) (local parser (require :parser.parser)) (local array (require :lib.array)) (local http (require :lib.http)) (local number (require :lib.number)) (local fetcher (require :fetcher)) (local json (require :vendor.json)) (fn format-url [path page] (.. "https://store.tildaapi.com/api/getproductslist/" "?storepartuid=" path "&slice=" page "&recid=644733406" "&c=1738164538594" "&getparts=true" "&getoptions=true" "&size=36")) (fn destruct-response [response] {:items (. (json.decode response) :products)}) (fn normalize [product] (local gallery (json.decode product.gallery)) (local weight (parser.guess-weight product.title ["г"])) (local price (number.string->number product.price)) (when (~= product.quantity "0") {:site "suhexuan" :url product.url :title product.title :description product.text ;; FIXME: parse all editions into different products :image (if (< 0 (# gallery)) (. gallery 1 :img) "") :weight weight :volume (or (parser.guess-volume product.text) (parser.guess-volume product.title)) :price price :price-per (if (and price weight (< 0 weight)) (/ (math.ceil (* (/ price weight) 10)) 10) nil) :characteristics product.characteristics})) (fn products [] (fetcher.from-json [{:path "896764703561" :tags ["Посуда"]} {:path "343222834961" :tags ["Разное"]} {:path "167733677091&filters[charact:6272182]=Зеленый" :tags ["Зеленый чай"]} {:path "167733677091&filters[charact:6272182]=Белый" :tags ["Белый чай"]} {:path "167733677091&filters[charact:6272182]=Желтый" :tags ["Желтый чай"]} {:path "167733677091&filters[charact:6272182]=Красный" :tags ["Красный чай"]} {:path "167733677091&filters[charact:6272182]=Черный" :tags ["Хэй ча"]} {:path "167733677091&filters[charact:6272182]=Шу+пуэр" :tags ["Шу пуэр"]} {:path "167733677091&filters[charact:6272182]=Шэн+пуэр" :tags ["Шэн пуэр"]} {:path "167733677091&filters[charact:6272182]=С+ароматами" :tags []} {:path "167733677091&filters[charact:6272182]=Улун" :tags ["Улун"]}] format-url destruct-response normalize)) {:products products :title "СуХэСюань" :url "https://suhexuan.ru"}