71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
// notifications dumps the full /msg/others/ page watch / journal /
|
|
// comment / fav / shout notifications, single fetch, all categories.
|
|
// Requires FA_A / FA_B in env (and ideally CF_CLEARANCE + FA_UA).
|
|
//
|
|
// go run ./examples/notifications
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
fa "git.anthrove.art/public/go-fa-api"
|
|
)
|
|
|
|
func main() {
|
|
a, b := os.Getenv("FA_A"), os.Getenv("FA_B")
|
|
if a == "" || b == "" {
|
|
log.Fatal("FA_A and FA_B must be set notifications require login")
|
|
}
|
|
client := fa.New(
|
|
fa.WithCookies(fa.Cookies{A: a, B: b}),
|
|
fa.WithCloudflare(fa.CFCookies{Clearance: os.Getenv("CF_CLEARANCE")}),
|
|
fa.WithUserAgent(envOr("FA_UA", "go-fa-api-example/0.1")),
|
|
)
|
|
|
|
n, err := client.Notifications(context.Background())
|
|
if err != nil {
|
|
log.Fatalf("Notifications: %v", err)
|
|
}
|
|
|
|
section("Journals", len(n.Journals))
|
|
for _, j := range n.Journals {
|
|
fmt.Printf(" [%d] %s by %s (%s, %s)\n",
|
|
j.JournalID, j.Title, j.Author.DisplayName, j.Rating,
|
|
j.PostedAt.Format("2006-01-02 15:04"))
|
|
}
|
|
section("New watchers", len(n.Watches))
|
|
for _, w := range n.Watches {
|
|
fmt.Printf(" %s (%s)\n", w.User.DisplayName, w.WatchedAt.Format("2006-01-02 15:04"))
|
|
}
|
|
section("Submission comments", len(n.SubmissionComments))
|
|
for _, c := range n.SubmissionComments {
|
|
fmt.Printf(" on submission %d (%q) by %s\n", c.OnSubmission, c.OnTitle, c.Author.DisplayName)
|
|
}
|
|
section("Journal comments", len(n.JournalComments))
|
|
for _, c := range n.JournalComments {
|
|
fmt.Printf(" on journal %d (%q) by %s\n", c.OnJournal, c.OnTitle, c.Author.DisplayName)
|
|
}
|
|
section("Favorites", len(n.Favorites))
|
|
for _, f := range n.Favorites {
|
|
fmt.Printf(" %s favorited %d (%q)\n", f.Favoriter.DisplayName, f.SubmissionID, f.SubmissionTitle)
|
|
}
|
|
section("Shouts", len(n.Shouts))
|
|
for _, s := range n.Shouts {
|
|
fmt.Printf(" shout from %s (%s)\n", s.Author.DisplayName, s.PostedAt.Format("2006-01-02 15:04"))
|
|
}
|
|
}
|
|
|
|
func section(name string, count int) {
|
|
fmt.Printf("\n=== %s (%d) ===\n", name, count)
|
|
}
|
|
|
|
func envOr(key, fallback string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return fallback
|
|
}
|