blob: b7699e90f02bfe6e82f666f72e1f12902e870011 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
(import-macros {: map} :lib.macro)
(local peg
(if (pick-values 1 (pcall require :lpeg))
(require :lpeg)
(require :lpeglj)))
(local parser (require :parser.parser))
(local number (require :lib.number))
(local fetcher (require :fetcher))
(fn format-url [path page]
(.. "https://chaekshop.ru/catalog/" path "?page=" page))
(local data-v-peg
(* (peg.P "data-v-") (^ (+ parser.pegs.letters parser.pegs.number) 1)))
(local product-peg
(*
(parser.anywhere
(parser.tag :a {data-v-peg "" :href (peg.Cg (parser.till "\"") :url)
:class "*" :itemprop "url" :section_id "*"}))
(parser.anywhere
(parser.tag :img {:src (peg.Cg (parser.till "\"") :image)
:alt "*"
:title (peg.Cg (parser.till "\"") :title)
:loading "lazy"
data-v-peg ""}))
(parser.anywhere
(parser.tag :p {:itemprop "price" :class "*" data-v-peg ""}
(* (peg.Cg (^ (+ parser.pegs.number " " ",") 1) :price) "₽")))
(parser.anywhere
(parser.tag :p {:class "*" data-v-peg ""}
(+ (* (peg.Cg parser.pegs.number :weight) " грамм")
(* parser.pegs.number " шт"))))))
(fn normalize [product]
(local weight (or (number.string->number product.weight)
(parser.guess-weight product.title)))
(local price (number.string->number (string.gsub product.price "," ".")))
{:site "chaekshop"
:id (.. "https://chaekshop.ru" product.url)
:title product.title
:url (.. "https://chaekshop.ru" product.url)
:description ""
:image (.. "https://chaekshop.ru" product.image)
:year (parser.guess-year product.title)
:price price
:weight weight
:price-per (if (and price weight (< 0 weight))
(/ (math.ceil (* (/ price weight) 10)) 10)
nil)})
(fn products []
(fetcher.from-html
[{:path "chay/belyy_chay" :tags ["Белый чай"]}
{:path "chay/guandunskie_uluny" :tags ["Улун"]}
{:path "chay/zhyeltyy_chay" :tags ["Желтый чай"]}
{:path "chay/zelyenyy_chay" :tags ["Зеленый чай"]}
{:path "chay/krasnyy_chay" :tags ["Красный чай"]}
{:path "chay/severo_futszyanskie_uluny" :tags ["Улун"]}
{:path "chay/tayvanskie_uluny" :tags ["Улун"]}
{:path "chay/khey_cha" :tags ["Хэй ча"]}
{:path "chay/shen_puer" :tags ["Шен пуэр"]}
{:path "chay/shu_puery" :tags ["Шу пуэр"]}
{:path "chay/yuzhno_futszyanskie_uluny_" :tags ["Улун"]}
{:path "chay/yunnanskie_uluny" :tags ["Улун"]}
{:path "chay/gaba_chay" :tags ["Улун"]}
{:path "chay/na_kazhdyy_den"}
{:path "chay/eksklyuziv"}
{:path "posuda_i_aksessuary/pialy" :tags ["Посуда"]}
{:path "posuda_i_aksessuary/isinskaya_glina" :tags ["Посуда"]}
{:path "posuda_i_aksessuary/keramika_iz_tszindechzhen" :tags ["Посуда"]}
{:path "posuda_i_aksessuary/keramika_iz_tszyanshuy" :tags ["Посуда"]}
{:path "posuda_i_aksessuary/kolby_termosy_nabory" :tags ["Посуда"]}
{:path "posuda_i_aksessuary/chabani" :tags ["Посуда"]}
{:path "posuda_i_aksessuary/chaynye_figurki" :tags ["Посуда"]}
{:path "posuda_i_aksessuary/slivniki" :tags ["Посуда"]}
{:path "posuda_i_aksessuary/gayvani" :tags ["Посуда"]}
{:path "posuda_i_aksessuary/keramika_iz_tsinchzhou" :tags ["Посуда"]}
{:path "posuda_i_aksessuary/aksessuary"}
{:path "posuda_i_aksessuary/pialy_tszindechzhen" :tags ["Посуда"]}
{:path "posuda_i_aksessuary/keramika_dekhua" :tags ["Посуда"]}
{:path "posuda_i_aksessuary/chayniki_iz_farfora" :tags ["Посуда"]}]
format-url
product-peg
normalize))
{: products :title "Чаёк" :url "https://chaekshop.ru"}
|