// inbox prints the logged-in user's new submissions the "what's new // from people you watch" feed at https://www.furaffinity.net/msg/submissions/. // // Requires FA_A and FA_B (session cookies). CF_CLEARANCE + FA_UA are // strongly recommended without them FurAffinity's Cloudflare layer will // usually serve a challenge page instead of the inbox. // // go run ./examples/inbox # first page (~72 items) // go run ./examples/inbox 3 # up to 3 cursor pages (~216 items) package main import ( "context" "errors" "fmt" "log" "os" "strconv" fa "git.anthrove.art/public/go-fa-api" ) func main() { maxPages := 1 if len(os.Args) >= 2 { if n, err := strconv.Atoi(os.Args[1]); err == nil && n > 0 { maxPages = n } } a, b := os.Getenv("FA_A"), os.Getenv("FA_B") if a == "" || b == "" { log.Fatal("FA_A and FA_B must be set the submission inbox requires login") } //if os.Getenv("CF_CLEARANCE") == "" || os.Getenv("FA_UA") == "" { // log.Println("warning: CF_CLEARANCE / FA_UA not set expect a Cloudflare challenge") //} 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")), // JSON-first listing parse: more resilient to FA markup tweaks, // and populates each item's author avatar URL. fa.WithExperimentalJSONListings(false), ) count := 0 for sub, err := range client.SubmissionInbox(context.Background(), fa.ListOptions{MaxPages: maxPages}) { if err != nil { switch { case errors.Is(err, fa.ErrCloudflareChallenge): log.Fatal("Cloudflare challenge refresh CF_CLEARANCE + FA_UA from your browser and retry") case errors.Is(err, fa.ErrUnauthorized): log.Fatal("unauthorized FA_A / FA_B are missing or expired") default: log.Fatalf("SubmissionInbox: %v", err) } } count++ when := "—" if !sub.PostedAt.IsZero() { when = sub.PostedAt.Format("2006-01-02 15:04") } fmt.Printf("[%d] %-50.50s %-8s by %s (%s)\n", sub.ID, sub.Title, sub.Rating, sub.Author.DisplayName, when) } fmt.Printf("\n%d new submission(s) across up to %d page(s)\n", count, maxPages) } func envOr(key, fallback string) string { if v := os.Getenv(key); v != "" { return v } return fallback }