From 92d95b978bfb10fd29024d0adda7b28f125e08b8 Mon Sep 17 00:00:00 2001 From: unwox Date: Tue, 15 Oct 2024 14:49:46 +0600 Subject: adapt to the new convention for calling luna module methods --- fetcher.fnl | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'fetcher.fnl') diff --git a/fetcher.fnl b/fetcher.fnl index 6a133f0..b3db8f0 100644 --- a/fetcher.fnl +++ b/fetcher.fnl @@ -8,6 +8,7 @@ (local json (require :vendor.json)) (local parser (require :parser.parser)) (local http (require :lib.http)) +(local {: must} (require :lib.utils)) (fn retry [what times sleep] (var result nil) @@ -33,17 +34,18 @@ (fn gather [page knil] (local url (url-formatter path page)) (print (.. "requesting " url)) - (local (status _ html) - (luna.http.request "GET" url {:User-Agent (http.random-user-agent)} "")) + (local {: status : body} + (must + (luna.http.request "GET" url {:User-Agent (http.random-user-agent)} ""))) - (if (= status 200) - (let [items (parser.match-many html item-peg)] + (if (= 200 status) + (let [items (parser.match-many body item-peg)] (if (or (= items nil) (= 0 (# items))) knil (do - (os.execute "sleep 1") + (os.execute "sleep .3") (gather (+ page 1) (array.concat knil items))))) - (= status 404) + (= 404 status) knil (retry #(gather page knil) 3 1))) @@ -75,16 +77,17 @@ (fn gather [page knil] (local url (url-formatter path page)) (print (.. "requesting " url)) - (local (status _ content) - (luna.http.request - "GET" url - {:User-Agent (http.random-user-agent) - :Content-Type "application/json" - :Accept "application/json"} - "")) + (local {: status : body} + (must + (luna.http.request + "GET" url + {:User-Agent (http.random-user-agent) + :Content-Type "application/json" + :Accept "application/json"} + ""))) (if (= status 200) - (let [{: items} (response-destructor (json.decode content))] + (let [{: items} (response-destructor (json.decode body))] (if (or (= items nil) (= 0 (# items))) knil (do -- cgit v1.2.3