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.fnl1
-rw-r--r--parser/gorkovchay.fnl1
-rw-r--r--parser/ipuer.fnl2
-rw-r--r--parser/moychay.fnl1
-rw-r--r--parser/ozchai.fnl7
-rw-r--r--parser/parser.fnl21
8 files changed, 32 insertions, 5 deletions
diff --git a/parser/artoftea.fnl b/parser/artoftea.fnl
index 265e19b..773f038 100644
--- a/parser/artoftea.fnl
+++ b/parser/artoftea.fnl
@@ -44,7 +44,6 @@
(local weight (number.string->number product.weight))
(local price (number.string->number product.price))
{:site "artoftea"
- :id product.id
:title product.title
:url product.url
:description product.description
@@ -52,6 +51,7 @@
:year year
:price price
:weight weight
+ :volume (parser.guess-volume product.title)
:price-per (if (and price weight (< 0 weight))
(/ (math.ceil (* (/ price weight) 10)) 10)
nil)})
diff --git a/parser/chaekshop.fnl b/parser/chaekshop.fnl
index 68046c1..21ed49b 100644
--- a/parser/chaekshop.fnl
+++ b/parser/chaekshop.fnl
@@ -38,7 +38,6 @@
(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 ""
@@ -46,6 +45,7 @@
:year (parser.guess-year product.title)
:price price
:weight weight
+ :volume (parser.guess-volume product.title)
:price-per (if (and price weight (< 0 weight))
(/ (math.ceil (* (/ price weight) 10)) 10)
nil)})
diff --git a/parser/clubcha.fnl b/parser/clubcha.fnl
index 23f9484..affee2b 100644
--- a/parser/clubcha.fnl
+++ b/parser/clubcha.fnl
@@ -72,6 +72,7 @@
:year 0
:price price
:weight weight
+ :volume (parser.guess-volume product.title)
:price-per (if (and price weight (< 0 weight))
(/ (math.ceil (* (/ price weight) 10)) 10)
nil)})
diff --git a/parser/gorkovchay.fnl b/parser/gorkovchay.fnl
index d094b85..890fffb 100644
--- a/parser/gorkovchay.fnl
+++ b/parser/gorkovchay.fnl
@@ -59,6 +59,7 @@
:price price
:archived product.archived
:weight weight
+ :volume (parser.guess-volume product.title)
:price-per price})
(fn products []
diff --git a/parser/ipuer.fnl b/parser/ipuer.fnl
index 7a1ae6b..c1a8da7 100644
--- a/parser/ipuer.fnl
+++ b/parser/ipuer.fnl
@@ -52,7 +52,6 @@
(local weight (parser.guess-weight product.title))
(local price (number.string->number product.price))
{:site "ipuer"
- :id product.id
:url (.. "https://ipuer.ru" product.url)
:title product.title
:description product.description
@@ -60,6 +59,7 @@
:year (parser.guess-year product.title)
: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)
diff --git a/parser/moychay.fnl b/parser/moychay.fnl
index 565992e..cec6a77 100644
--- a/parser/moychay.fnl
+++ b/parser/moychay.fnl
@@ -33,6 +33,7 @@
:title product.name
:archived (not product.available)
:weight weight
+ :volume (parser.guess-volume product.name)
:price price
:image (.. "https://moychay.ru" product.image)
:url (.. "https://moychay.ru" product.url)
diff --git a/parser/ozchai.fnl b/parser/ozchai.fnl
index 16a3265..937a35b 100644
--- a/parser/ozchai.fnl
+++ b/parser/ozchai.fnl
@@ -1,5 +1,6 @@
(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))
@@ -23,6 +24,11 @@
(local gallery (json.decode product.gallery))
(local weight (number.string->number (. product.editions 1 :Вес)))
(local price (number.string->number (. product.editions 1 :price)))
+ (var volume nil)
+ (each [_ c (ipairs product.characteristics)]
+ (when (= (. c :title) "Объем")
+ (set volume (parser.guess-volume c.value))))
+
{:site "ozchai"
:id product.url
:url product.url
@@ -33,6 +39,7 @@
(. gallery 1 :img)
"")
:weight weight
+ :volume volume
:price price
:price-per (if (and price weight (< 0 weight))
(/ (math.ceil (* (/ price weight) 10)) 10)
diff --git a/parser/parser.fnl b/parser/parser.fnl
index bf8feed..55296f2 100644
--- a/parser/parser.fnl
+++ b/parser/parser.fnl
@@ -107,7 +107,6 @@
(fn guess-tags [text]
(local text (if text (must (luna.utf8.lower text)) ""))
-
(if (: (anywhere (peg.P "зеленый чай")) :match text)
["Зеленый чай"]
(: (anywhere (peg.P "улун")) :match text)
@@ -142,10 +141,27 @@
(if text
(number.string->number
(: (anywhere
+ ;; FIXME: also account for kilograms
(* (peg.C pegs.number) (maybe " ") "гр"))
:match text))
nil))
+(fn guess-volume [text]
+ (if text
+ (let [peg (peg.Ct
+ (anywhere
+ (* (peg.C pegs.number)
+ (maybe " ")
+ ;; also account for litres
+ (+ (* (peg.C "л") (+ (peg.P " ") "\n" -1))
+ (peg.C "мл")))))]
+ (let [result (peg:match text)]
+ (if result
+ (let [[number metric] result]
+ (* number (if (= metric "л") 1000 1)))
+ nil)))
+ nil))
+
{: match-many
: tag
: anywhere
@@ -155,4 +171,5 @@
:not pnot
: guess-tags
: guess-year
- : guess-weight}
+ : guess-weight
+ : guess-volume}