Compare commits

...

9 Commits

Author SHA1 Message Date
db6c0f6cc2 Update README.md 2024-06-25 15:40:28 +02:00
25adc4410d Update README.md 2024-06-25 15:02:47 +02:00
b77a69e634 Update README.md 2024-06-25 13:39:01 +02:00
1e448c3f31 Update README.md 2024-06-25 11:45:03 +02:00
99899bd49e Update README.md 2024-06-25 11:31:33 +02:00
f90cc7d2a0 Removed logs and don't overwrite existing markdown files 2024-06-24 19:05:37 +02:00
1341dd2833 Update README.md 2024-06-24 09:09:39 +02:00
260b946f25 Update README.md 2024-06-23 22:33:28 +02:00
15ae3f241f Added server url in main args 2024-06-23 22:31:47 +02:00
3 changed files with 52 additions and 27 deletions

View File

@ -5,41 +5,48 @@ _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.
Each Markdown file will contain:
- A link to the original post
- The author's handle
- The post's content in HTML
- The media attachments locally downloaded
- If available, the alt text for each media
- [x] A link to the original post
- [x] The author's handle
- [x] The post's content in HTML
- [x] The media attachments locally downloaded
- [x] If available, the alt text for each media
- [ ] The full thread, if applicable
- [ ] The link card, if any
Most of these values will be in the form of `key:: value` for easy integration with Obsidian's plugin Dataview. A sample script is available [here](./dataview-query.js)
## Setup & Run
## Build & Run
### Pre-requirements
```sh
# Required by the httprequest dependency
$ sudo apt install libcurl4-openssl-dev
```
- Clone this repository
- Install Janet and jpm https://janet-lang.org/
- Get an access token for your Mastodon account
![](image1.png)
![](image2.png)
- Run the program
### Run
```sh
$ ./mastodon-bookmarks YOUR_APP_TOKEN
# Install dependencies locally with -l (--local)
$ jpm deps -l
# Tell jpm that our dependencies are local, before starting the script
$ jpm -l janet main.janet YOUR_INSTANCE YOUR_APP_TOKEN
```
## Development
The `YOUR_INSTANCE` value **must not** have the trailing slash (e.g: `https://hachyderm.io`)
- Clone this repository
- Install Janet and jpm https://janet-lang.org/
- `jpm deps --local`
### Build for release
```sh
$ janet main.janet YOUR_APP_TOKEN
```
## Build binary
```sh
$ jpm build
$ jpm build -l
```
## LICENSE

View File

@ -2,9 +2,11 @@
(import spork/json :as json)
(import ./utils :as utils)
(var server "")
(var apptoken "")
(var dbg false)
(def urls @["https://hachyderm.io/api/v1/bookmarks"])
(def urls @[])
(def save-path "./bookmarks/")
(def done @[])
@ -13,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"
@ -96,8 +105,12 @@
(defn main [& args]
(set apptoken (or (os/getenv "TOKEN") (args 1)))
(set dbg (get args 2))
(set server (args 1))
(set apptoken (args 2))
(set dbg (get args 3))
(array/push urls (string server "/api/v1/bookmarks"))
(os/mkdir "./bookmarks")
(os/mkdir "./bookmarks/attachments")
(download-bookmarks))

View File

@ -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 {})