Files
go-fa-api/examples/gallery_dump/main.go
2026-05-25 22:27:18 +02:00

55 lines
1.3 KiB
Go

// gallery_dump iterates a user's gallery (authenticated) and prints the
// title and ID of every submission encountered, honouring the SDK's default
// 1 req/sec rate limit.
//
// Required environment variables:
//
// FA_A — the `a` session cookie
// FA_B — the `b` session cookie
// CF_CLEARANCE — the cf_clearance cookie from the same browser session
// FA_UA — the User-Agent string that produced CF_CLEARANCE
//
// Usage:
//
// go run ./examples/gallery_dump <username> [maxPages]
package main
import (
"context"
"fmt"
"log"
"os"
"strconv"
fa "git.anthrove.art/public/go-fa-api"
)
func main() {
if len(os.Args) < 2 {
log.Fatalf("usage: %s <username> [maxPages]", os.Args[0])
}
user := os.Args[1]
maxPages := 0
if len(os.Args) >= 3 {
if n, err := strconv.Atoi(os.Args[2]); err == nil {
maxPages = n
}
}
client := fa.New(
fa.WithCookies(fa.Cookies{A: os.Getenv("FA_A"), B: os.Getenv("FA_B")}),
fa.WithCloudflare(fa.CFCookies{Clearance: os.Getenv("CF_CLEARANCE")}),
fa.WithUserAgent(os.Getenv("FA_UA")),
)
count := 0
for sub, err := range client.Gallery(context.Background(), user, fa.ListOptions{MaxPages: maxPages}) {
if err != nil {
log.Fatalf("iter: %v", err)
}
count++
fmt.Printf("[%d] %s %s\n", sub.ID, sub.Title, sub.Rating)
}
fmt.Printf("\n%d submissions\n", count)
}