summaryrefslogtreecommitdiff
path: root/parser
diff options
context:
space:
mode:
Diffstat (limited to 'parser')
-rw-r--r--parser/artoftea.fnl2
-rw-r--r--parser/chaekshop.fnl2
-rw-r--r--parser/clubcha.fnl2
-rw-r--r--parser/ipuer.fnl2
-rw-r--r--parser/moychay.fnl73
-rw-r--r--parser/ozchai.fnl4
6 files changed, 79 insertions, 6 deletions
diff --git a/parser/artoftea.fnl b/parser/artoftea.fnl
index a62cd34..83ff0ea 100644
--- a/parser/artoftea.fnl
+++ b/parser/artoftea.fnl
@@ -81,4 +81,4 @@
product-peg
normalize))
-{: products :title "Art of tea" :url "https://artoftea.ru"}
+{:products products :title "Art of tea" :url "https://artoftea.ru"}
diff --git a/parser/chaekshop.fnl b/parser/chaekshop.fnl
index 80e6cd5..68046c1 100644
--- a/parser/chaekshop.fnl
+++ b/parser/chaekshop.fnl
@@ -85,4 +85,4 @@
product-peg
normalize))
-{: products :title "Чаёк" :url "https://chaekshop.ru"}
+{:products products :title "Чаёк" :url "https://chaekshop.ru"}
diff --git a/parser/clubcha.fnl b/parser/clubcha.fnl
index 57334a7..23f9484 100644
--- a/parser/clubcha.fnl
+++ b/parser/clubcha.fnl
@@ -127,4 +127,4 @@
product-peg
normalize))
-{: products :title "Железный Феникс" :url "https://clubcha.ru"}
+{:products products :title "Железный Феникс" :url "https://clubcha.ru"}
diff --git a/parser/ipuer.fnl b/parser/ipuer.fnl
index b501a35..7a1ae6b 100644
--- a/parser/ipuer.fnl
+++ b/parser/ipuer.fnl
@@ -77,4 +77,4 @@
product-peg
normalize))
-{: products :title "Институт чая пуэр" :url "https://ipuer.ru"}
+{:products products :title "Институт чая пуэр" :url "https://ipuer.ru"}
diff --git a/parser/moychay.fnl b/parser/moychay.fnl
new file mode 100644
index 0000000..565992e
--- /dev/null
+++ b/parser/moychay.fnl
@@ -0,0 +1,73 @@
+(local peg
+ (if (pick-values 1 (pcall require :lpeg))
+ (require :lpeg)
+ (require :lpeglj)))
+(local number (require :lib.number))
+(local fetcher (require :fetcher))
+(local json (require :vendor.json))
+(local parser (require :parser.parser))
+(local libhtml (require :lib.html))
+
+(fn extract-data [html]
+ (libhtml.unescape
+ (: (parser.anywhere
+ (parser.tag
+ :div
+ {:id "app" :data-page (peg.Cg (parser.till "\""))}))
+ :match html)))
+
+(fn format-url [path page]
+ (.. "https://moychay.ru/catalog/" path "?page=" (tostring page)))
+
+(fn destruct-response [response]
+ {:items (. (json.decode (extract-data response)) :props :catalog :products)})
+
+(fn normalize [product]
+ (local weight
+ (if (~= product.measurement_unit "шт")
+ (. product.variations 1 :weight)
+ 0))
+ (local price (number.string->number (. product.variations 1 :price)))
+ {:site "moychay"
+ :url product.url
+ :title product.name
+ :archived (not product.available)
+ :weight weight
+ :price price
+ :image (.. "https://moychay.ru" product.image)
+ :url (.. "https://moychay.ru" product.url)
+ :price-per (if (and price weight (< 0 weight))
+ (/ (math.ceil (* (/ price weight) 10)) 10)
+ nil)
+ :characteristics product.characteristics})
+
+(fn products []
+ (fetcher.from-json
+ [{:path "krasnyj_chaj" :tags ["Красный чай"]}
+ {:path "belyj_chaj" :tags ["Белый чай"]}
+ {:path "zheltyj_chaj" :tags ["Желтый чай"]}
+ {:path "ulun/yuzhnofudzyanskij_ulun" :tags ["Улун" "Фудзянь"]}
+ {:path "ulun/uishanskij_ulun" :tags ["Улун" "Фудзянь"]}
+ {:path "ulun/guandunskij_ulun" :tags ["Улун" "Гуандун"]}
+ {:path "ulun/tajvanskij_ulun" :tags ["Улун" "Тайвань"]}
+ {:path "indian_tea" :tags ["Индийский чай"]}
+ {:path "gruzinskij_chaj" :tags ["Грузинский чай"]}
+ {:path "chernyj_cha" :tags ["Хэй ча"]}
+ {:path "thailand-tea" :tags ["Тайландский чай"]}
+ {:path "vietnamese-tea" :tags ["Вьетнамский чай"]}
+ {:path "mate" :tags ["Йерба мате"]}
+ {:path "posuda" :tags ["Посуда"]}
+ {:path "puer/shu_puer_pressovannyj" :tags ["Шу пуэр"]}
+ {:path "puer/shu_puer_rassypnoj" :tags ["Шу пуэр"]}
+ {:path "puer/shen_puer_pressovannyj" :tags ["Шен пуэр"]}
+ {:path "puer/shen_puer_rassypnoj" :tags ["Шен пуэр"]}
+ {:path "puer/purpurnyj_shen_puer" :tags ["Шен пуэр"]}
+ {:path "puer/belyj_puer" :tags ["Белый пуэр"]}
+ {:path "jasmin" :tags ["Жасминовый чай"]}
+ {:path "green_tea" :tags ["Зеленый чай"]}
+ {:path "gaba-tea" :tags ["Улун" "Габа"]}]
+ format-url
+ destruct-response
+ normalize))
+
+{:products products :title "Мойчай.ру" :url "https://moychay.ru"}
diff --git a/parser/ozchai.fnl b/parser/ozchai.fnl
index 9ccce5f..16a3265 100644
--- a/parser/ozchai.fnl
+++ b/parser/ozchai.fnl
@@ -17,7 +17,7 @@
"&size=36"))
(fn destruct-response [response]
- {:items response.products})
+ {:items (. (json.decode response) :products)})
(fn normalize [product]
(local gallery (json.decode product.gallery))
@@ -54,4 +54,4 @@
destruct-response
normalize))
-{: products :title "Чайная #OZCHAI" :url "https://ozchai.ru"}
+{:products products :title "Чайная #OZCHAI" :url "https://ozchai.ru"}