diff options
Diffstat (limited to 'janet/fedi-playground/src/play.janet')
-rw-r--r-- | janet/fedi-playground/src/play.janet | 36 |
1 files changed, 36 insertions, 0 deletions
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 |