From e8af8b886ac22084d0ff0f53dde392a3c40cd6a6 Mon Sep 17 00:00:00 2001 From: elioat Date: Thu, 13 Jul 2023 09:19:47 -0400 Subject: * --- janet/fedi-playground/src/play.janet | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 janet/fedi-playground/src/play.janet (limited to 'janet/fedi-playground/src/play.janet') diff --git a/janet/fedi-playground/src/play.janet b/janet/fedi-playground/src/play.janet new file mode 100644 index 0000000..4dd9c75 --- /dev/null +++ b/janet/fedi-playground/src/play.janet @@ -0,0 +1,36 @@ +# a utility script used to explore my fediverse followers +(use spork) + +(defn read-from-file [file-path] + "read data from a file, not super safe or fault tolerant." + (let [f (file/open file-path :r) + content (file/read f :all)] + (file/close f) + content)) + +(def json-data + (read-from-file "followers.json")) # this is just a small sample export, will have to use curl to get the full list beyond the first 80 + +(def all-followers + (json/decode json-data)) + +# this seems horribly inefficient +# TODO: is there a clever way to deal with this? +# maybe a filter? +# (filter (fn [x] (> x 2)) [1 2 3 4 5]) # @[3 4 5] +# or maybe keep? +# https://janetdocs.com/keep +(defn select-by-key [key arr] + "select a value by matched key." + (def a @[]) + (each follower arr + (loop [[k v] :pairs follower] + (if (= k key) + (array/push a v)))) + a) + +(def follower-accounts + (select-by-key "acct" all-followers)) + +(def follower-usernames + (select-by-key "username" all-followers)) \ No newline at end of file -- cgit 1.4.1-2-gfad0