From fe1755043fec6aaa923dd414e81e340cbf48b8f8 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Fri, 21 Jun 2024 22:59:04 +0200 Subject: [PATCH] First commit --- .gitignore | 2 ++ README.md | 8 ++++++++ main.janet | 34 ++++++++++++++++++++++++++++++++++ project.janet | 7 +++++++ 4 files changed, 51 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 main.janet create mode 100644 project.janet diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..692880d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build +jpm_tree \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d914461 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +## Install dependencies + +`jpm deps --local + +## Build + +`jpm build` + diff --git a/main.janet b/main.janet new file mode 100644 index 0000000..c89177b --- /dev/null +++ b/main.janet @@ -0,0 +1,34 @@ +(import httprequest :as r) +(import spork/json :as json) + +(def url "https://hachyderm.io/api/v1/bookmarks") +(def auth "REDACTED") + +(defn download-bookmarks [] + "Downloads the bookmarks and saves them to a file." + (def response + (r/get url {"Authorization" (string "Bearer " auth)} {})) + (def links ((response :headers) "Link")) + (pp links) + (def bookmarks (json/decode (response :body))) + (def fout (file/open "./response.json" :w)) + (file/write fout (json/encode bookmarks))) + +(defn write-markdown [item] + (def id (item "id")) + (def fout (file/open (string "./" id ".md") :w)) + (file/write fout (item "content")) + (file/close fout)) + +(defn write-files [] + "Writes the bookmarks to files." + (def fin (file/open "./response.json" :r)) + (print (file/read fin :all)) + (def bookmarks (json/decode (file/read fin :all))) + (each item bookmarks + (write-markdown item))) + +(defn main [& args] + (download-bookmarks) + # (write-files) + (print "ok")) diff --git a/project.janet b/project.janet new file mode 100644 index 0000000..d9ca857 --- /dev/null +++ b/project.janet @@ -0,0 +1,7 @@ +(declare-project + :name "mastodon-test" + :dependencies ["https://github.com/meinside/httprequest-janet"]) + +(declare-executable + :name "mastodon-test" + :entry "main.janet") \ No newline at end of file