Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f90cc7d2a0 | ||
|
|
1341dd2833 | ||
|
|
260b946f25 |
@@ -1,5 +1,7 @@
|
||||
# Mastodon Bookmarks Archive
|
||||
|
||||
[Release download](https://git.scambier.xyz/scambier/janet-mastodon-bookmarks/releases)
|
||||
|
||||
_A small Janet script to archive all your Mastodon bookmarks in Markdown files._
|
||||
|
||||
Because Mastodon posts can disappear for a variety of reasons (deletion, defederation, server instance shutdown, ...), it is safer to archive your bookmarks.
|
||||
@@ -26,7 +28,7 @@ Most of these values will be in the form of `key:: value` for easy integration w
|
||||
$ ./mastodon-bookmarks YOUR_INSTANCE YOUR_APP_TOKEN
|
||||
```
|
||||
|
||||
The `YOUR_INSTANCE` value must not have trailing slash (e.g: `https://hachyderm.io`)
|
||||
The `YOUR_INSTANCE` value must not have the trailing slash (e.g: `https://hachyderm.io`)
|
||||
|
||||
## Development
|
||||
|
||||
|
||||
+10
-3
@@ -15,20 +15,27 @@
|
||||
"Downloads the media from the item."
|
||||
(def files @[])
|
||||
(def media (item "media_attachments"))
|
||||
(pp (item "media_attachments"))
|
||||
(if dbg
|
||||
(pp (item "media_attachments")))
|
||||
(each m media
|
||||
(def url (m "url"))
|
||||
(def folder (string save-path "attachments/"))
|
||||
(array/push files {:path (string "./attachments/" (utils/get-image url folder))
|
||||
:description (m "description")}))
|
||||
(pp files)
|
||||
(if dbg (pp files))
|
||||
files)
|
||||
|
||||
|
||||
(defn write-markdown [item]
|
||||
(def files (download-media item))
|
||||
(def id (item "id"))
|
||||
(def fout (file/open (string save-path id ".md") :w))
|
||||
(def path (string save-path id ".md"))
|
||||
|
||||
(if (utils/exists? path)
|
||||
(do
|
||||
(print (string "Skipping " id))
|
||||
(break)))
|
||||
(def fout (file/open path :w))
|
||||
|
||||
(def inline (string
|
||||
"mastodon-url:: " (item "url") " \n"
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
(import httprequest :as r)
|
||||
|
||||
(def exists? (fn [path]
|
||||
"Returns whether a file exists at the specified path."
|
||||
(def f (file/open path :r))
|
||||
(if f (do (file/close f) true) false)))
|
||||
|
||||
(defn get-image [url folder &named headers opts]
|
||||
"Download an image from a URL and save it to a file. Returns the path to the saved file."
|
||||
(default headers {})
|
||||
|
||||
Reference in New Issue
Block a user