aboutsummaryrefslogtreecommitdiff
path: root/cmds/polite.go
diff options
context:
space:
mode:
authorSam Scholten2026-10-20 10:51:46 +1000
committerSam Scholten2026-10-20 10:51:46 +1000
commit04bb657bb3573d00d92c1748058a61c1612d48fd (patch)
tree15b2d33a7bbaa2be27aaab3fba4a3ee1eca9e618 /cmds/polite.go
parent8027bac07b61e631866f253632ce7aa4476982db (diff)
downloadfluxrec-04bb657bb3573d00d92c1748058a61c1612d48fd.tar.gz
fluxrec-04bb657bb3573d00d92c1748058a61c1612d48fd.zip
polite: fetch-light sweep (scraper off + HTTP cache honored) on every feedHEADmain
Diffstat (limited to 'cmds/polite.go')
-rw-r--r--cmds/polite.go85
1 files changed, 85 insertions, 0 deletions
diff --git a/cmds/polite.go b/cmds/polite.go
new file mode 100644
index 0000000..2701436
--- /dev/null
+++ b/cmds/polite.go
@@ -0,0 +1,85 @@
+// Polite command: one-off sweep making every feed a polite fetcher.
+//
+// Sends PUT /v1/feeds/{id} with the two-field body {"crawler":false,
+// "ignore_http_cache":false} per subscription: no original-article scraping
+// and HTTP cache (conditional requests) honored. That is the strategy
+// against origins blocking the polling — per poll cycle the origin sees only
+// the (cheap, mostly 304) feed fetch, not a page request per new entry.
+// Only those two fields are ever sent, so no other feed setting can move
+// (Miniflux's update is pointer-based: omitted fields stay untouched).
+// Fail-fast + idempotent: an interrupted run is resumed by simply rerunning.
+//
+// Side effect worth knowing: with the scraper off, future entries carry the
+// feed-provided content (often an excerpt) instead of the scraped article —
+// serve's RSS bodies will follow suit. Title-only scoring is unaffected.
+package cmds
+
+import (
+ "flag"
+ "fmt"
+ "io"
+
+ "fluxrec/miniflux"
+)
+
+type PoliteCommand struct {
+ DryRun bool
+}
+
+func (c *PoliteCommand) Name() string { return "polite" }
+
+func (c *PoliteCommand) Init(args []string) error {
+ fs := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
+ fs.Usage = func() {
+ fmt.Fprint(fs.Output(), `Usage: fluxrec polite [--dry-run]
+
+Make every feed a polite fetcher: scraper off, HTTP cache honored. Each feed
+is updated with the two-field body {"crawler":false,"ignore_http_cache":false}
+— nothing else on the feed changes. Stops at the first feed that errors
+(naming it and the remainder); rerun at will, the op is idempotent.
+--dry-run lists the feeds without sending anything.
+`)
+ fs.PrintDefaults()
+ }
+ fs.BoolVar(&c.DryRun, "dry-run", false, "List the feeds and exit (no PUT sent)")
+ if err := fs.Parse(args); err != nil {
+ return err
+ }
+ return nil
+}
+
+func (c *PoliteCommand) Run(stdin io.Reader, stdout io.Writer) error {
+ cfg, err := miniflux.ConfigFromEnv()
+ if err != nil {
+ return err
+ }
+ client := miniflux.NewClient(cfg)
+
+ feeds, err := client.Feeds()
+ if err != nil {
+ return err
+ }
+
+ // API order, one update at a time: a subscription list is small, and
+ // serialized requests keep any failure's story simple.
+ done := 0
+ for _, f := range feeds {
+ if c.DryRun {
+ fmt.Fprintf(stdout, "would %-6d %s\n", f.ID, clip(f.Title, 64))
+ continue
+ }
+ if err := client.MakeFeedPolite(f.ID); err != nil {
+ return fmt.Errorf("updating feed %d (%s): %w; rerun polite to finish the remaining %d (idempotent)",
+ f.ID, f.Title, err, len(feeds)-done)
+ }
+ done++
+ fmt.Fprintf(stdout, "ok %-6d %s\n", f.ID, clip(f.Title, 64))
+ }
+
+ if c.DryRun {
+ fmt.Fprintf(stdout, "dry-run: would set crawler=false and ignore_http_cache=false on all %d feeds; nothing was sent\n", len(feeds))
+ return nil
+ }
+ fmt.Fprintf(stdout, "polite sweep: scraper off + HTTP cache honored on %d of %d feeds\n", done, len(feeds))
+ return nil
+}