summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-12-11 20:41:29 +0600
committerunwox <me@unwox.com>2024-12-16 21:20:55 +0600
commit155c9c5bbb703490e5d61f7b4504987e35088a95 (patch)
tree643995b9b90c3759888cfd9b3100d871c0ccfb63 /bin
parente35dbf50a93ba734def634317a09211654974d42 (diff)
integrate moychay.ru tea shop
Diffstat (limited to 'bin')
-rw-r--r--bin/fetch.fnl13
-rw-r--r--bin/serve.fnl16
2 files changed, 10 insertions, 19 deletions
diff --git a/bin/fetch.fnl b/bin/fetch.fnl
index a3155a4..006cbea 100644
--- a/bin/fetch.fnl
+++ b/bin/fetch.fnl
@@ -6,6 +6,7 @@
(local array (require :lib.array))
(local cache (require :lib.cache))
+(local moychay (require :parser.moychay))
(local ozchai (require :parser.ozchai))
(local ipuer (require :parser.ipuer))
(local artoftea (require :parser.artoftea))
@@ -101,7 +102,7 @@
(.. "INSERT OR REPLACE INTO products VALUES "
(array.join
(map (fn [_ _] "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
- products)
+ products)
", ")))
(local creation-time (now))
(local vars
@@ -117,7 +118,7 @@
(or product.price 0)
(or product.weight 0)
(or product.price-per 0)
- false
+ (or product.archived false)
creation-time]))
products []))
(must (luna.db.exec-tx tx sql vars))
@@ -150,12 +151,8 @@
;; replace with with-tx
(local tx (must (luna.db.begin db)))
(must (luna.db.exec-tx tx "DELETE FROM product_tags;" []))
-(each [_ products (pairs [chaekshop.products
- clubcha.products
- artoftea.products
- ipuer.products
- ozchai.products])]
- (store-products tx (products)))
+(each [_ parser (pairs [chaekshop clubcha artoftea ipuer ozchai moychay])]
+ (store-products tx (parser.products)))
(cache.clear-tx tx "page:")
(must (luna.db.commit tx))
diff --git a/bin/serve.fnl b/bin/serve.fnl
index 5cfc535..9329bf1 100644
--- a/bin/serve.fnl
+++ b/bin/serve.fnl
@@ -5,6 +5,7 @@
(local math (require :math))
(local fennel (require :vendor.fennel))
(local html (require :vendor.html))
+(local libhtml (require :lib.html))
(local json (require :vendor.json))
(local array (require :lib.array))
(local str (require :lib.string))
@@ -57,15 +58,6 @@
"термос" "бутылка"
"бутылка" "термос"})
-(fn unescape [s]
- (assert (= (type s) :string) "s must be string")
- (pick-values 1
- (-> s
- (string.gsub "&lt;" "<")
- (string.gsub "&gt;" ">")
- (string.gsub "&quot;" "\"")
- (string.gsub "&amp;" "&"))))
-
(fn sanitize-input [input]
(if input
(str.trim (input:gsub "[=()<>']" "") " ")
@@ -333,7 +325,9 @@
:alt product.title} ""]]
(site-name-template product.site)
[:a {:href link :style "text-decoration: none;" :rel "nofollow"}
- [:NO-ESCAPE (.. "<div class=\"title\">" (unescape product.title) "</div>")]]
+ [:NO-ESCAPE (.. "<div class=\"title\">"
+ (libhtml.unescape product.title)
+ "</div>")]]
[:div {:class "price"}
(if product.price (.. (str.format-price product.price) "₽") "")
(if (< 0 product.weight)
@@ -447,7 +441,7 @@
[:option {:value val
:selected (if (= form.site val) "selected" nil)}
(. (require (.. "parser." val)) :title)])
- [:ozchai :clubcha :ipuer :artoftea :chaekshop]))]]
+ [:ozchai :clubcha :ipuer :artoftea :chaekshop :moychay]))]]
[:div {}
[:select {:name "sort"}
[:option {:value ""} "~ Порядок ~"]