diff options
| -rw-r--r-- | bin/fetch.fnl | 5 | ||||
| -rw-r--r-- | bin/serve.fnl | 4 | ||||
| -rw-r--r-- | etc/everytea-fetch.service | 2 | ||||
| -rw-r--r-- | parser/thailandtea.fnl | 64 | ||||
| -rw-r--r-- | static/thailandtea.webp | bin | 0 -> 1188 bytes |
5 files changed, 70 insertions, 5 deletions
diff --git a/bin/fetch.fnl b/bin/fetch.fnl index a28af42..286c2ef 100644 --- a/bin/fetch.fnl +++ b/bin/fetch.fnl @@ -8,8 +8,8 @@ (local artoftea (require :parser.artoftea)) (local batatcha (require :parser.batatcha)) -(local chaibez (require :parser.chaibez)) (local chaekshop (require :parser.chaekshop)) +(local chaibez (require :parser.chaibez)) (local clubcha (require :parser.clubcha)) (local daochai (require :parser.daochai)) (local gorkovchay (require :parser.gorkovchay)) @@ -20,6 +20,7 @@ (local suhexuan (require :parser.suhexuan)) (local tea108 (require :parser.tea108)) (local teaworkshop (require :parser.teaworkshop)) +(local thailandtea (require :parser.thailandtea)) (local yoceramics (require :parser.yoceramics)) (when _G.unpack @@ -196,7 +197,7 @@ (each [_ parser (pairs [batatcha yoceramics daochai gorkovchay ozchai suhexuan ipuer artoftea clubcha chaekshop kolokolnikovchai - tea108 teaworkshop chaibez moychay])] + tea108 teaworkshop chaibez thailandtea moychay])] (let [(ok? products) (pcall parser.products)] (if (and ok? (< 0 (# products))) (do diff --git a/bin/serve.fnl b/bin/serve.fnl index 036e43d..c0128c2 100644 --- a/bin/serve.fnl +++ b/bin/serve.fnl @@ -451,8 +451,8 @@ :selected (if (= form.site val) "selected" nil)} (. (require (.. "parser." val)) :title)]) [:suhexuan :ozchai :batatcha :kolokolnikovchai :yoceramics :tea108 - :ipuer :clubcha :daochai :chaekshop :teaworkshop :chaibez - :artoftea :moychay :gorkovchay]))]] + :ipuer :clubcha :daochai :thailandtea :chaekshop :teaworkshop + :chaibez :artoftea :moychay :gorkovchay]))]] [:div {} [:select {:name "sort"} [:option {:value ""} "~ Порядок ~"] diff --git a/etc/everytea-fetch.service b/etc/everytea-fetch.service index e18a5e5..ea8edcc 100644 --- a/etc/everytea-fetch.service +++ b/etc/everytea-fetch.service @@ -6,7 +6,7 @@ Wants=everytea-fetch.timer Type=oneshot User=root WorkingDirectory=/root/everytea.ru -ExecStart=/usr/local/bin/luna -n 1 /root/everytea.ru/main.lua /root/everytea.ru/bin/fetch.fnl +ExecStart=/usr/local/bin/luna -n 1 /root/everytea.ru/bin/fetch.fnl [Install] WantedBy=multi-user.target diff --git a/parser/thailandtea.fnl b/parser/thailandtea.fnl new file mode 100644 index 0000000..ba4ac1c --- /dev/null +++ b/parser/thailandtea.fnl @@ -0,0 +1,64 @@ +(import-macros {: map} :lib.macro) + +(local number (require :lib.number)) +(local str (require :lib.string)) +(local fetcher (require :fetcher)) +(local json (require :vendor.json)) + +(fn format-url [path page] + (.. "https://store.tildaapi.com/api/getproductslist/" + "?storepartuid=" path + "&slice=" page + "&recid=1117084816" + "&c=1759202174912" + "&getparts=true" + "&getoptions=true" + "&size=36")) + +(fn destruct-response [response] + {:items (. (json.decode response) :products)}) + +(fn normalize [product] + (local gallery (json.decode product.gallery)) + (local edition (. product.editions 1)) + (local weight (number.string->number edition.Вес)) + (local price (number.string->number product.price)) + (local title + (if (string.match product.title "/") + (str.trim (. (str.split product.title "/") 2)) + product.title)) + + ;; removing products with weight > 100: these are for buying in bulk. + (when (and (~= product.quantity "0") weight (< weight 100)) + {:site "thailandtea" + :url product.url + :title title + :description product.text + ;; FIXME: parse all editions into different products + :image (if (< 0 (# gallery)) + (. gallery 1 :img) + "") + :weight weight + :volume 0 + :price price + :price-per (if (and price weight (< 0 weight)) + (/ (math.ceil (* (/ price weight) 10)) 10) + nil) + :characteristics product.characteristics})) + +(fn products [] + (fetcher.from-json + [{:path "598539851691" :tags ["Шен пуэр"]} + {:path "336610050931" :tags ["Шу пуэр"]} + {:path "336610050931" :tags ["Хэй ча"]} + {:path "301615446601" :tags ["Улун"]} + {:path "563074948861" :tags ["Улун" "Габа"]} + {:path "232469549561" :tags ["Красный чай"]} + {:path "189665932031" :tags ["Белый чай"]}] + format-url + destruct-response + normalize)) + +{:products products + :title "HUBAR TEA" + :url "https://thailand-tea.ru"} diff --git a/static/thailandtea.webp b/static/thailandtea.webp Binary files differnew file mode 100644 index 0000000..943d4b8 --- /dev/null +++ b/static/thailandtea.webp |
