mirror of
https://github.com/adulau/mastodon-markdown-archive.git
synced 2024-11-21 17:37:06 +00:00
Implement --persist behavior and add logs
This commit is contained in:
parent
1868600b98
commit
b97d050c93
2 changed files with 14 additions and 0 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
@ -94,6 +95,8 @@ func (c Client) GetPosts(filter PostsFilter) ([]Post, error) {
|
|||
query,
|
||||
)
|
||||
|
||||
log.Println(fmt.Sprintf("Fetching posts from %s", postsUrl))
|
||||
|
||||
if err := get(postsUrl, &posts); err != nil {
|
||||
return posts, err
|
||||
}
|
||||
|
|
11
main.go
11
main.go
|
@ -6,6 +6,7 @@ import (
|
|||
"git.hq.ggpsv.com/gabriel/mastodon-pesos/client"
|
||||
"git.hq.ggpsv.com/gabriel/mastodon-pesos/files"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -15,6 +16,7 @@ func main() {
|
|||
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")
|
||||
persist := flag.Bool("persist", false, "Persist most recent post id to /tmp/mastodon-pesos-fid")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
|
@ -41,10 +43,19 @@ func main() {
|
|||
log.Panicln(err)
|
||||
}
|
||||
|
||||
log.Println(fmt.Sprintf("Fetched %d posts", len(posts)))
|
||||
|
||||
for _, post := range posts {
|
||||
if err := fileWriter.Write(post); err != nil {
|
||||
log.Panicln("error writing post to file: %w", err)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if *persist && len(posts) > 0 {
|
||||
lastPost := posts[0]
|
||||
|
||||
fid := []byte(lastPost.Id)
|
||||
os.WriteFile("/tmp/mastodon-pesos-fid", fid, 0644)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue