diff options
Diffstat (limited to 'site/ozchai.fnl')
| -rw-r--r-- | site/ozchai.fnl | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/site/ozchai.fnl b/site/ozchai.fnl deleted file mode 100644 index 90c4edc..0000000 --- a/site/ozchai.fnl +++ /dev/null @@ -1,70 +0,0 @@ -(import-macros {: map} :lib.macro) - -(local http (require :http)) -(local array (require :lib.array)) -(local json (require :vendor.json)) - -(local %all-products-partuid 176163172341) - -(fn string->number [str] - (if str - (tonumber (pick-values 1 (str:gsub "[^0-9.]" ""))) - nil)) - -(fn request [partuid slice] - (print (.. "https://store.tildaapi.com/api/getproductslist/" - "?storepartuid=" - partuid - "&recid=280779251&c=1723216515077" - "&getparts=true&getoptions=true&slice=%d&size=36")) - (let [(status headers body) - (luna.http.request - "GET" - (string.format - (.. "https://store.tildaapi.com/api/getproductslist/" - "?storepartuid=" - partuid - "&recid=280779251&c=1723216515077" - "&getparts=true&getoptions=true&slice=%d&size=36") - slice) - {:Content-Type "application/json" - :User-Agent (http.random-user-agent)} - "")] - (json.decode body))) - -(fn walk-slices [partuid] - (fn gather [slice knil] - (let [{: nextslice : products} (request partuid slice) - res (array.concat knil products)] - (if (= 0 (# products)) - knil - (do - (os.execute "sleep 1") - (gather (+ slice 1) res))))) - (gather 1 [])) - -(fn normalize [_ product] - (local gallery (json.decode product.gallery)) - (local weight (string->number (. (. product.editions 1) :Вес))) - (local price (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 [] - (map normalize (walk-slices %all-products-partuid))) - -{: products} |
