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:
		
							parent
							
								
									461c2c02ba
								
							
						
					
					
						commit
						8fc5e4bc3c
					
				|  | @ -29,6 +29,7 @@ | |||
|           options.enable = lib.mkEnableOption "Dhyan daily runner"; | ||||
|         in | ||||
|         { | ||||
|           # TODO This won't work either because secrets aren't passed  | ||||
|           options.services.mossnet.dhyan = options; | ||||
|           config = lib.mkIf serviceConfig.enable { | ||||
|             systemd.services."dhyan" = { | ||||
|  |  | |||
|  | @ -40,32 +40,22 @@ | |||
| 
 | ||||
| (def token (generate-token (System/getenv "SHAARLI_TOKEN"))) | ||||
| 
 | ||||
| (defn shaarli-request [offset] | ||||
|   (-> (curl/get (str "http://links.mossnet.lan/api/v1/links?searchtags=music&limit=" offset) {:headers {"Authorization" (str "Bearer " token)}}) | ||||
| (defn shaarli-request [limit offset] | ||||
|   (-> (curl/get (str "http://links.mossnet.lan/api/v1/links?searchtags=music&limit=" limit "&offset=" offset) {:headers {"Authorization" (str "Bearer " token)}}) | ||||
|       (:body) | ||||
|       (json/parse-string true))) | ||||
| 
 | ||||
| (defn get-all-shaarli-data | ||||
|   ([] (get-all-shaarli-data {} 0)) | ||||
|   ([data offset] | ||||
|    (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)))))) | ||||
|   [] | ||||
|   (shaarli-request "all" 0)) | ||||
| 
 | ||||
| (comment | ||||
|   (shaarli-request 0) | ||||
|   (shaarli-request 100 0) | ||||
|   (count (get-all-shaarli-data)) | ||||
|   (url-filterer {:url "bandcamp"} "bandcamp") | ||||
|   (filter (fn [x] (.contains (get x :url) "bandcamp")) [{:url "bandcamp"}]) | ||||
|   (println "somestring") | ||||
|   (.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 | ||||
|     (let [algo "HmacSHA256" | ||||
|           mac (Mac/getInstance algo)] | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue