summaryrefslogtreecommitdiff
path: root/site/ozchai.fnl
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-09-27 15:26:33 +0600
committerunwox <me@unwox.com>2024-09-27 15:44:16 +0600
commitdd449357f502dbe9ca4487d4b06a06ee4e597146 (patch)
tree9847488a6cc2c1aaf1fc80578e1a7a5d4af99ff5 /site/ozchai.fnl
parent9b82db238f9e2e02a76f95c793f8d6ef2387ecfd (diff)
new structure
Diffstat (limited to 'site/ozchai.fnl')
-rw-r--r--site/ozchai.fnl70
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}