summaryrefslogtreecommitdiff
path: root/parser
diff options
context:
space:
mode:
Diffstat (limited to 'parser')
-rw-r--r--parser/artoftea.fnl3
-rw-r--r--parser/tea108.fnl67
2 files changed, 69 insertions, 1 deletions
diff --git a/parser/artoftea.fnl b/parser/artoftea.fnl
index 5c7efff..1af4969 100644
--- a/parser/artoftea.fnl
+++ b/parser/artoftea.fnl
@@ -7,7 +7,8 @@
(local fetcher (require :fetcher))
(fn format-url [path page]
- (.. "https://artoftea.ru/" path "/?page=" page))
+ (.. "https://artoftea.ru/" path
+ "/" (if (< 1 page) (.. "?page=" page) "")))
(local product-peg
(*
diff --git a/parser/tea108.fnl b/parser/tea108.fnl
new file mode 100644
index 0000000..d575716
--- /dev/null
+++ b/parser/tea108.fnl
@@ -0,0 +1,67 @@
+(import-macros {: map} :lib.macro)
+
+(local peg
+ (if (pick-values 1 (pcall require :lpeg))
+ (require :lpeg)
+ (require :lpeglj)))
+(local number (require :lib.number))
+(local parser (require :parser.parser))
+(local fetcher (require :fetcher))
+(local utils (require :lib.utils))
+
+(fn format-url [path page]
+ (.. "https://tea108.ru/shop/" path "/?page=" page))
+
+(local product-peg
+ (*
+ ;; a delimiter to clearly separate products
+ (parser.anywhere "data-productid=")
+ ;; url
+ (parser.anywhere
+ (parser.tag :a {:href (peg.Cg (parser.till "\"") :url)
+ :class "product js--hover-preview"}))
+ ;; image
+ (parser.anywhere (* "data-src=\""
+ (peg.Cg (parser.till "\"") :image)
+ "\""))
+ ;; name
+ (parser.anywhere
+ (parser.tag :div {:class "product-name"}
+ (peg.Cg (parser.till "</div>") :title)))
+ ;; price
+ (parser.anywhere
+ (parser.tag :span {:class (* "product-price-min" (parser.till "\""))}
+ (peg.Cg (parser.till "</span>") :price)))))
+
+(fn normalize [product]
+ (local weight (parser.guess-weight product.title [(* "г" (parser.not "."))]))
+ (local price (number.string->number product.price))
+
+ {:site "tea108"
+ :url product.url
+ :title product.title
+ :description product.description
+ :image (.. "https:" product.image)
+ :price price
+ :weight weight
+ :volume (parser.guess-volume product.title)
+ :category product.category
+ :price-per (if (and price weight (< 0 weight))
+ (/ (math.ceil (* (/ price weight) 10)) 10)
+ nil)})
+
+(fn products []
+ (fetcher.from-html
+ [{:path "wu-yi-yan-cha" :tags ["Улун" "Фуцзянь"]}
+ {:path "feng-huang-dancong" :tags ["Улун" "Дань Цун"]}
+ {:path "taiwan-oolong" :tags ["Улун" "Тайвань"]}
+ {:path "hong-cha" :tags ["Красный чай"]}
+ {:path "bai-cha" :tags ["Белый чай"]}
+ {:path "sheng" :tags ["Шен пуэр"]}
+ {:path "shu-puer" :tags ["Шу пуэр"]}
+ {:path "tea-ware" :tags ["Посуда"]}]
+ format-url
+ product-peg
+ normalize))
+
+{:products products :title "Tea108" :url "https://tea108.ru"}