From 1ca444d3e659b61317ea62588930a0a5156934c5 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 20 Apr 2024 22:58:30 -0600 Subject: imworkingon: Initial go at daily statuses --- cmd/generate/src_mastodon.go | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 cmd/generate/src_mastodon.go (limited to 'cmd/generate/src_mastodon.go') 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 +} -- cgit v1.2.3-54-g00ecf