summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2025-02-03 12:33:46 +0600
committerunwox <me@unwox.com>2025-02-03 12:33:58 +0600
commit38467b38372e21ad17960797e41cc650fb70bf77 (patch)
treed1f6f7acc46311e63514649e6abfe20270b6ec86
parent20e9d84fe9481bd0b8db839127a60bf29ec88014 (diff)
add kolokolnikovchai parser
-rw-r--r--bin/fetch.fnl3
-rw-r--r--bin/serve.fnl2
-rw-r--r--parser/chaekshop.fnl2
-rw-r--r--parser/kolokolnikovchai.fnl80
-rw-r--r--parser/ozchai.fnl3
-rw-r--r--static/kolokolnikovchai.pngbin0 -> 17354 bytes
6 files changed, 85 insertions, 5 deletions
diff --git a/bin/fetch.fnl b/bin/fetch.fnl
index e7ee454..2edcdac 100644
--- a/bin/fetch.fnl
+++ b/bin/fetch.fnl
@@ -14,6 +14,7 @@
(local artoftea (require :parser.artoftea))
(local clubcha (require :parser.clubcha))
(local chaekshop (require :parser.chaekshop))
+(local kolokolnikovchai (require :parser.kolokolnikovchai))
(local {: must} (require :lib.utils))
(when _G.unpack
@@ -163,7 +164,7 @@
(must (luna.db.commit tx)))
(each [_ parser (pairs [gorkovchay moychay ozchai suhexuan ipuer artoftea
- clubcha chaekshop])]
+ clubcha chaekshop kolokolnikovchai])]
(local products (parser.products))
(when (< 0 (# products))
;; replace with with-tx
diff --git a/bin/serve.fnl b/bin/serve.fnl
index 927bd71..9373f16 100644
--- a/bin/serve.fnl
+++ b/bin/serve.fnl
@@ -492,7 +492,7 @@
:selected (if (= form.site val) "selected" nil)}
(. (require (.. "parser." val)) :title)])
[:ozchai :suhexuan :clubcha :ipuer :artoftea :chaekshop :moychay
- :gorkovchay]))]]
+ :kolokolnikovchai :gorkovchay]))]]
[:div {}
[:select {:name "sort"}
[:option {:value ""} "~ Порядок ~"]
diff --git a/parser/chaekshop.fnl b/parser/chaekshop.fnl
index 21ed49b..53c0271 100644
--- a/parser/chaekshop.fnl
+++ b/parser/chaekshop.fnl
@@ -12,7 +12,7 @@
(.. "https://chaekshop.ru/catalog/" path "?page=" page))
(local data-v-peg
- (* (peg.P "data-v-") (^ (+ parser.pegs.letters parser.pegs.number) 1)))
+ (* (peg.P "data-v-") (^ (+ parser.pegs.lat-letters parser.pegs.number) 1)))
(local product-peg
(*
diff --git a/parser/kolokolnikovchai.fnl b/parser/kolokolnikovchai.fnl
new file mode 100644
index 0000000..cc5d723
--- /dev/null
+++ b/parser/kolokolnikovchai.fnl
@@ -0,0 +1,80 @@
+(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=280779251"
+ "&c=1723216515077"
+ "&getparts=true"
+ "&getoptions=true"
+ "&size=36"))
+
+(fn destruct-response [response]
+ {:items (. (json.decode response) :products)})
+
+(fn normalize [product]
+ (var weight nil)
+
+ (when product.characteristics
+ (each [_ c (ipairs product.characteristics)]
+ (when (= (. c :title) "Вес")
+ (set weight (parser.guess-weight c.value ["г"])))))
+
+ (when (and product.properties (not weight))
+ (each [_ c (ipairs product.properties)]
+ (when (= (. c :title) "Выберите вес:") ;; FRAGILE!
+ (set weight (parser.guess-weight c.values ["г"])))))
+
+ (when (~= product.quantity "0")
+ (local gallery (json.decode product.gallery))
+ (local price (number.string->number (. product.editions 1 :price)))
+
+ {:site "kolokolnikovchai"
+ :url product.url
+ :title product.title
+ :description product.descr
+ ;; FIXME: parse all editions into different products
+ :image (if (< 0 (# gallery))
+ (. gallery 1 :img)
+ "")
+ :weight weight
+ :volume (or (parser.guess-volume product.descr)
+ (parser.guess-volume product.text))
+ :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 "409075863661" :tags ["Красный чай"]}
+ {:path "754089666541" :tags ["Красный чай"]}
+ {:path "372064040221" :tags ["Шу пуэр"]}
+ {:path "454350410711" :tags ["Хэй ча"]}
+ {:path "841704512611" :tags ["Шен пуэр"]}
+ {:path "848263867181" :tags ["Белый чай"]}
+ {:path "990406163191" :tags ["Зеленый чай"]}
+ {:path "451142994821" :tags ["Улун"]}
+ {:path "770906787081" :tags ["Габа"]}
+ {:path "909586139961" :tags ["Посуда"]} ;; чайники
+ {:path "351075619951" :tags ["Посуда"]} ;; гайвани
+ {:path "874916565001" :tags ["Посуда"]} ;; пиалы
+ {:path "927453990401" :tags ["Посуда"]} ;; чахаи
+ {:path "242398612931" :tags ["Посуда"]} ;; чайные доски
+ {:path "208270710991" :tags ["Посуда"]} ;; чайные аксессуары
+ {:path "542771614531" :tags ["Посуда"]} ;; заварники
+ ]
+ format-url
+ destruct-response
+ normalize))
+
+{:products products :title "Колокольников Чай" :url "https://kolokolnikovchai.ru"}
diff --git a/parser/ozchai.fnl b/parser/ozchai.fnl
index 937a35b..1d4c4f3 100644
--- a/parser/ozchai.fnl
+++ b/parser/ozchai.fnl
@@ -30,10 +30,9 @@
(set volume (parser.guess-volume c.value))))
{:site "ozchai"
- :id product.url
:url product.url
:title product.title
- :description product.descr
+ :description product.descr
;; FIXME: parse all editions into different products
:image (if (< 0 (# gallery))
(. gallery 1 :img)
diff --git a/static/kolokolnikovchai.png b/static/kolokolnikovchai.png
new file mode 100644
index 0000000..55f6e22
--- /dev/null
+++ b/static/kolokolnikovchai.png
Binary files differ