From b97d050c9336a6c09983039efd863b40454f35ef Mon Sep 17 00:00:00 2001 From: Gabriel Garrido Date: Sun, 21 Apr 2024 19:51:55 +0200 Subject: [PATCH] Implement --persist behavior and add logs --- client/client.go | 3 +++ main.go | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/client/client.go b/client/client.go index 06c1881..5095f76 100644 --- a/client/client.go +++ b/client/client.go @@ -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 } diff --git a/main.go b/main.go index 63e280b..a373d0a 100644 --- a/main.go +++ b/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) + } }