summaryrefslogtreecommitdiff
path: root/parser/batatcha.fnl
diff options
context:
space:
mode:
Diffstat (limited to 'parser/batatcha.fnl')
-rw-r--r--parser/batatcha.fnl56
1 files changed, 56 insertions, 0 deletions
diff --git a/parser/batatcha.fnl b/parser/batatcha.fnl
new file mode 100644
index 0000000..0d88ee0
--- /dev/null
+++ b/parser/batatcha.fnl
@@ -0,0 +1,56 @@
+(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=995758736"
+ "&c=1748185006948"
+ "&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 (or (parser.guess-weight (. product.editions 1 :Вес) ["г"])
+ (number.string->number (. product.editions 1 :Вес))))
+ (local price (number.string->number (. product.editions 1 :price)))
+ (var volume (parser.guess-volume product.title))
+
+ {:site "batatcha"
+ :url product.url
+ :title product.title
+ :description product.descr
+ :image (if (< 0 (# gallery)) (. gallery 1 :img) "")
+ :weight weight
+ :volume volume
+ :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 "252209460212" :tags ["Посуда"]}
+ {:path "547479831241" :tags ["Шу пуэр"]}
+ {:path "826048744931" :tags ["Улун"]}
+ {:path "979435309971" :tags ["Красный чай"]}
+ {:path "770446922881" :tags ["Зеленый чай"]}
+ {:path "770679255051" :tags ["Белый чай"]}
+ {:path "596866221302" :tags ["Тизан"]}]
+ format-url
+ destruct-response
+ normalize))
+
+{:products products :title "батат абрикос земля мята" :url "https://batatcha.com"}