Support min and max id

This commit is contained in:
Gabriel Garrido 2024-04-21 20:10:25 +02:00
parent 308d257926
commit 621d5eee8f
3 changed files with 23 additions and 5 deletions

View file

@ -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
```

View file

@ -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())

View file

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