diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-04-20 22:58:30 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-04-20 22:58:30 -0600 |
commit | 1ca444d3e659b61317ea62588930a0a5156934c5 (patch) | |
tree | ecedc3e82487439d2e5da29f8f752b4049661a9e /cmd/generate/src_mastodon.go | |
parent | 0856e4aab26f88ab0573f9227561ea0d80bcb352 (diff) |
imworkingon: Initial go at daily statuses
Diffstat (limited to 'cmd/generate/src_mastodon.go')
-rw-r--r-- | cmd/generate/src_mastodon.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/cmd/generate/src_mastodon.go b/cmd/generate/src_mastodon.go new file mode 100644 index 0000000..42ae8b2 --- /dev/null +++ b/cmd/generate/src_mastodon.go @@ -0,0 +1,52 @@ +package main + +import ( + "html/template" + "net/url" + "slices" + "time" +) + +type MastodonStatus struct { + ID string `json:"id"` + CreatedAt time.Time `json:"created_at"` + URL string `json:"url"` + Content template.HTML `json:"content"` +} + +// Returns statuses sorted from newest to oldest. +func ReadStandups(server, username string) ([]*MastodonStatus, error) { + var account struct { + ID string `json:"id"` + } + if err := httpGetJSON(server+"/api/v1/accounts/lookup?acct="+username, &account); err != nil { + return nil, err + } + var statuses []*MastodonStatus + for { + params := make(url.Values) + params.Set("tagged", "DailyStandUp") + params.Set("exclude_reblogs", "true") + if len(statuses) > 0 { + params.Set("max_id", statuses[len(statuses)-1].ID) + } + var resp []*MastodonStatus + if err := httpGetJSON(server+"/api/v1/accounts/"+account.ID+"/statuses?"+params.Encode(), &resp); err != nil { + return nil, err + } + if len(resp) == 0 { + break + } + statuses = append(statuses, resp...) + } + + ignoreList := []string{ + "https://fosstodon.org/@lukeshu/112198267818432116", + "https://fosstodon.org/@lukeshu/112198241414760456", + } + statuses = slices.DeleteFunc(statuses, func(status *MastodonStatus) bool { + return slices.Contains(ignoreList, status.URL) + }) + + return statuses, nil +} |