about summary refs log tree commit diff stats
path: root/janet/fedi-playground/src/play.janet
diff options
context:
space:
mode:
authorelioat <hi@eli.li>2023-07-13 09:19:47 -0400
committerelioat <hi@eli.li>2023-07-13 09:19:47 -0400
commite8af8b886ac22084d0ff0f53dde392a3c40cd6a6 (patch)
treee331f9a750331e0ba059ea1e6723fda92af9470e /janet/fedi-playground/src/play.janet
parent8fa9ccfb54e2ac8c86fae53c0e6395fa72fdc330 (diff)
downloadtour-e8af8b886ac22084d0ff0f53dde392a3c40cd6a6.tar.gz
*
Diffstat (limited to 'janet/fedi-playground/src/play.janet')
-rw-r--r--janet/fedi-playground/src/play.janet36
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