fix: bug which wasn't actually getting all shaarli requests, turns out

shaarli's api has limit: all which negates the need to do what i was
doing
This commit is contained in:
Anish Lakhwara 2022-08-30 21:33:53 +10:00
parent 461c2c02ba
commit 8fc5e4bc3c
2 changed files with 6 additions and 15 deletions

View file

@ -29,6 +29,7 @@
options.enable = lib.mkEnableOption "Dhyan daily runner"; options.enable = lib.mkEnableOption "Dhyan daily runner";
in in
{ {
# TODO This won't work either because secrets aren't passed
options.services.mossnet.dhyan = options; options.services.mossnet.dhyan = options;
config = lib.mkIf serviceConfig.enable { config = lib.mkIf serviceConfig.enable {
systemd.services."dhyan" = { systemd.services."dhyan" = {

View file

@ -40,32 +40,22 @@
(def token (generate-token (System/getenv "SHAARLI_TOKEN"))) (def token (generate-token (System/getenv "SHAARLI_TOKEN")))
(defn shaarli-request [offset] (defn shaarli-request [limit offset]
(-> (curl/get (str "http://links.mossnet.lan/api/v1/links?searchtags=music&limit=" offset) {:headers {"Authorization" (str "Bearer " token)}}) (-> (curl/get (str "http://links.mossnet.lan/api/v1/links?searchtags=music&limit=" limit "&offset=" offset) {:headers {"Authorization" (str "Bearer " token)}})
(:body) (:body)
(json/parse-string true))) (json/parse-string true)))
(defn get-all-shaarli-data (defn get-all-shaarli-data
([] (get-all-shaarli-data {} 0)) []
([data offset] (shaarli-request "all" 0))
(let [new-data (shaarli-request offset)
total-data (concat data new-data)
old-last (last data)
new-last (last new-data)]
(if (= old-last new-last)
total-data
(get-all-shaarli-data total-data (+ offset 100))))))
(comment (comment
(shaarli-request 0) (shaarli-request 100 0)
(count (get-all-shaarli-data)) (count (get-all-shaarli-data))
(url-filterer {:url "bandcamp"} "bandcamp") (url-filterer {:url "bandcamp"} "bandcamp")
(filter (fn [x] (.contains (get x :url) "bandcamp")) [{:url "bandcamp"}]) (filter (fn [x] (.contains (get x :url) "bandcamp")) [{:url "bandcamp"}])
(println "somestring") (println "somestring")
(.getBytes (str {"iat" (sh "date" "-u" "+%s")})) (.getBytes (str {"iat" (sh "date" "-u" "+%s")}))
(def signature (-> (Mac/getInstance "HmacSHA256")
(.init (SecretKeySpec. (.getBytes "test secret") "HmacSHA256"))
(.doFinal (.getBytes (str "header.payload") "UTF-8"))))
(def sig (def sig
(let [algo "HmacSHA256" (let [algo "HmacSHA256"
mac (Mac/getInstance algo)] mac (Mac/getInstance algo)]