From 621d5eee8f81ed7457e849dc9c186239b2950862 Mon Sep 17 00:00:00 2001 From: Gabriel Garrido Date: Sun, 21 Apr 2024 20:10:25 +0200 Subject: [PATCH] Support min and max id --- README.md | 10 +++++++--- client/client.go | 10 ++++++++++ main.go | 8 ++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1611ba9..3e71e7e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Mastodon PESOS -Fetch a Mastodon account's posts and save them as Markdown files. Posts are transformed to Markdown, images are inlined, and replies are threaded. +Fetch a Mastodon account's posts and save them as Markdown files. Posts are transformed to Markdown, images are inlined, and replies are threaded. Implements most of the parameters in Mastodon's [API to get account's statuses](https://docs.joinmastodon.org/methods/accounts/#statuses). For the time being this formats the files with [Hugo](https://gohugo.io) front-matter. @@ -10,17 +10,21 @@ I use this small tool to create an archive of my Mastodon posts, which I then [s ``` Usage of ./mastodon-pesos: -dist string - Path to directory where files will be written + Path to directory where files will be written (default "./posts") -exclude-reblogs Whether or not to exclude reblogs -exclude-replies Whether or not exclude replies to other users -limit int Maximum number of posts to fetch (default 40) + -max-id string + Fetch posts lesser than this id + -min-id string + Fetch posts immediately newer than this id -persist Persist most recent post id to /tmp/mastodon-pesos-fid -since-id string - Fetch only posts made since passed post id + Fetch posts greater than this id -user string URL of User's Mastodon account whose toots will be fetched ``` diff --git a/client/client.go b/client/client.go index 5095f76..c6d01cd 100644 --- a/client/client.go +++ b/client/client.go @@ -42,6 +42,8 @@ type PostsFilter struct { ExcludeReblogs bool Limit int SinceId string + MinId string + MaxId string } func New(userURL string) (Client, error) { @@ -84,6 +86,14 @@ func (c Client) GetPosts(filter PostsFilter) ([]Post, error) { queryValues.Add("since_id", filter.SinceId) } + if filter.MaxId != "" { + queryValues.Add("max_id", filter.MaxId) + } + + if filter.MinId != "" { + queryValues.Add("min_id", filter.MinId) + } + queryValues.Add("limit", strconv.Itoa(filter.Limit)) query := fmt.Sprintf("?%s", queryValues.Encode()) diff --git a/main.go b/main.go index a373d0a..970fb59 100644 --- a/main.go +++ b/main.go @@ -10,12 +10,14 @@ import ( ) func main() { - dist := flag.String("dist", "", "Path to directory where files will be written") + dist := flag.String("dist", "./posts", "Path to directory where files will be written") user := flag.String("user", "", "URL of User's Mastodon account whose toots will be fetched") excludeReplies := flag.Bool("exclude-replies", false, "Whether or not exclude replies to other users") excludeReblogs := flag.Bool("exclude-reblogs", false, "Whether or not to exclude reblogs") limit := flag.Int("limit", 40, "Maximum number of posts to fetch") - sinceId := flag.String("since-id", "", "Fetch only posts made since passed post id") + sinceId := flag.String("since-id", "", "Fetch posts greater than this id") + maxId := flag.String("max-id", "", "Fetch posts lesser than this id") + minId := flag.String("min-id", "", "Fetch posts immediately newer than this id") persist := flag.Bool("persist", false, "Persist most recent post id to /tmp/mastodon-pesos-fid") flag.Parse() @@ -31,6 +33,8 @@ func main() { ExcludeReblogs: *excludeReblogs, Limit: *limit, SinceId: *sinceId, + MaxId: *maxId, + MinId: *minId, }) if err != nil {