(import-macros {: map} :lib.macro) (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=280779251" "&c=1723216515077" "&getparts=true" "&getoptions=true" "&size=36")) (fn destruct-response [response] {:items response.products}) (fn normalize [product] (local gallery (json.decode product.gallery)) (local weight (number.string->number (. product.editions 1 :Вес))) (local price (number.string->number (. product.editions 1 :price))) {:site "ozchai" :id product.url :url product.url :title product.title :description product.descr ;; FIXME: parse all editions into different projects :image (if (< 0 (# gallery)) (. gallery 1 :img) "") :weight weight :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 "176163172341"}] format-url destruct-response normalize)) {: products}