Cookbook
Cookbook
Watch a topic for new pages
Run a search on a schedule and report only the dated pages you have not seen before.
1 min read · Updated 20 Nov 2026
On this page
Run this on a schedule, such as a daily cron job. It reports pages published in the last 180 days that it has not reported before, and remembers what it has seen in seen.json.
monitor.py
import jsonimport osfrom datetime import date, timedeltafrom pathlib import Pathimport requestsAPI = "https://fluxsearch.io/api/v1"SEEN = Path("seen.json")SINCE = (date.today() - timedelta(days=180)).isoformat()response = requests.post( f"{API}/search", headers={"Authorization": f"Bearer {os.environ['FLUX_API_KEY']}"}, json={"query": "sodium-ion battery factory announced", "max_results": 20, "enrich": 0}, timeout=120,)response.raise_for_status()seen = set(json.loads(SEEN.read_text())) if SEEN.exists() else set()fresh = [ r for r in response.json()["results"] if r["published_at"] and r["published_at"] >= SINCE and r["url"] not in seen]for result in sorted(fresh, key=lambda r: r["published_at"], reverse=True): print(result["published_at"], result["title"]) print(" ", result["url"])print(f"\n{len(fresh)} new since {SINCE}")SEEN.write_text(json.dumps(sorted(seen | {r["url"] for r in fresh})))import { existsSync, readFileSync, writeFileSync } from "node:fs";const API = "https://fluxsearch.io/api/v1";const SEEN = "seen.json";const SINCE = new Date(Date.now() - 180 * 86_400_000).toISOString().slice(0, 10);type Result = { url: string; title: string; published_at: string | null };const response = await fetch(`${API}/search`, { method: "POST", headers: { Authorization: `Bearer ${process.env.FLUX_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ query: "sodium-ion battery factory announced", max_results: 20, enrich: 0, }),});if (!response.ok) throw new Error(`Flux ${response.status}: ${await response.text()}`);const { results } = (await response.json()) as { results: Result[] };const seen = new Set<string>(existsSync(SEEN) ? JSON.parse(readFileSync(SEEN, "utf8")) : []);const fresh = results .filter((r) => r.published_at && r.published_at >= SINCE && !seen.has(r.url)) .sort((a, b) => b.published_at!.localeCompare(a.published_at!));for (const result of fresh) { console.log(result.published_at, result.title); console.log(" ", result.url);}console.log(`\n${fresh.length} new since ${SINCE}`);for (const r of fresh) seen.add(r.url);writeFileSync(SEEN, JSON.stringify([...seen].sort()));What it prints
Output
2026-07-23 GM Backs Sodium Ion Batteries for U.S. Grid Storage https://spectrum.ieee.org/sodium-ion-battery-peak-energy2026-07-08 First-of-its-kind sodium-ion battery plant to open in Sacramento's Metro ... https://www.cbsnews.com/sacramento/news/sacramento-metro-air-park-sodium-ion-battery-plant/2026-06-18 US sodium-ion startups form coalition to challenge China's battery ... https://www.energy-storage.news/us-sodium-ion-startups-form-coalition-to-challenge-chinas-battery-dominance/2026-06-10 GM to manufacture sodium-ion battery cells for Peak Energy BESS https://www.solarpowerworldonline.com/2026/06/gm-to-manufacture-sodium-ion-battery-cells-for-peak-energy-bess/2026-06-09 General Motors Is Bringing Sodium-Ion Battery Production To America https://insideevs.com/news/798154/general-motors-sodium-ion-battery-production/5 new since 2026-05-23How it works
- There is no date filter on search, so the script filters on
published_at. Results without a date are skipped. max_resultsis how many results are asked for. Fewer can come back.- The second run prints only what is new since the first.