about summary refs log blame commit diff stats
path: root/janet/fedi-playground/src/play.janet
blob: 4dd9c75c3200d17e0aa10f7069931b903315a27a (plain) (tree)



































                                                                                                                                         
# 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))