Menu

Integrations / Cookbook and starters

News watch

A Markdown brief of the day's new articles on your topics, with each article listed once.

Copy as MarkdownOpen in ChatGPT (opens in a new tab)Open in Claude (opens in a new tab)

AvailablePython 3.9+One file, nothing to installTested 2026-11-19

For each topic, one search of the news source over the last day (time_range: day), with the passage of each article that best matches the topic. Articles already in an earlier brief are skipped: their addresses are kept in seen.json beside the script.

1Get the code

news_watch.py
"""News watch: a daily brief of new articles on your topics, from the news source.

    export MILLIONSHORT_API_KEY=ms-YOUR_API_KEY
    python news_watch.py "heat pumps" "community energy" > brief.md

No package to install: Python 3.9 or later. One search per topic (1 credit each). Articles already
in an earlier brief are skipped: their addresses are kept in seen.json beside this file. Run it once
a day, from cron or any scheduler.
"""
import datetime
import json
import os
import sys
import urllib.error
import urllib.request
from pathlib import Path

API = os.environ.get("MILLIONSHORT_BASE_URL", "https://api.millionshort.com").rstrip("/")
SEEN = Path(__file__).with_name("seen.json")


def news(topic):
    body = {"query": topic, "sources": ["news"], "time_range": "day", "num_results": 10, "max_highlights": 1}
    request = urllib.request.Request(
        f"{API}/v1/search",
        data=json.dumps(body).encode(),
        headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"], "Content-Type": "application/json"},
    )
    with urllib.request.urlopen(request, timeout=60) as response:
        return json.load(response)["data"]["results"]


def main(topics):
    seen = set(json.loads(SEEN.read_text())) if SEEN.exists() else set()
    print(f"# News brief, {datetime.date.today():%d %B %Y}\n")
    try:
        for topic in topics:
            print(f"## {topic}\n")
            try:
                fresh = [r for r in news(topic) if r["url"] not in seen]
            except urllib.error.HTTPError as failure:
                print(f"The search failed ({failure.code}); this topic is tried again next time.\n")
                if failure.code in (401, 429):  # no key, or no credits or calls left: the next topics would fail too
                    break
                continue
            if not fresh:
                print("Nothing new.\n")
            for r in fresh:
                passage = (r.get("highlights") or [r.get("snippet") or ""])[0]
                print(f"- [{r['title']}]({r['url']}) ({r['site']}, {r.get('published_date') or 'no date'})")
                if passage:
                    print(f"  {passage[:240]}")
                seen.add(r["url"])
            print()
    finally:
        SEEN.write_text(json.dumps(sorted(seen)))


if __name__ == "__main__":
    main(sys.argv[1:] or ["heat pumps"])

2Run it

Shell
export MILLIONSHORT_API_KEY=ms-YOUR_API_KEY
python news_watch.py "home battery storage" "community energy" > brief.md

To get it every morning, run it from cron, for example 0 7 * * * with the key in the job's environment.

3What you get

brief.md (shortened)
# News brief, 19 November 2026

## home battery storage

- [US battery storage capacity exceeds 200 GWh — Electrek](https://ua.news/en/...) (ua.news, 2026-11-19)
  In the third quarter of 2026, 14.3 GWh of battery storage systems were installed in the United States ...
- [Why AI data centers need storage beyond conventional backup power](https://www.finanznachrichten.de/...) (finanznachrichten.de, 2026-11-19)
  AI data centers are changing the duty cycle expected of battery energy storage ...

## community energy

- [Why hip-hop moguls are pivoting to green energy investments](https://www.wokv.com/...) (wokv.com, 2026-11-18)
  However, community solar lets you benefit from green energy investments ...

Run it again the same day and each topic says "Nothing new." Broad topics also catch loose matches (a phone with a "massive battery"): quote a phrase, or narrow with include_domains.

4Change it

ToChange
A weekly brief"time_range": "week", and run it weekly
Only smaller outletsAdd "remove_top_sites": 1000
Discussions as well"sources": ["news", "discussions"] (1 credit per source)
Narrower resultsQuote the exact phrase in the topic, or name the sites with include_domains

Costs and limits

One search per topic a run: 1 credit each.

When it fails

What you seeWhyFix
401 AUTH_MISSING_KEY or AUTH_INVALID_KEYThe key is missing or wrongSet MILLIONSHORT_API_KEY; keys start with ms-
400 INVALID_PARAMA field name or value the API does not takeThe message names the field; the search reference lists them all
429 RATE_LIMITED or CAPACITYToo many calls a minute, or no free capacity right nowWait the Retry-After seconds, then retry
429 INSUFFICIENT_CREDITSThe plan's credits are used upStop and add credits; do not retry
The same story again under a new addressOutlets republish under new URLsMatch on titles too, or keep the brief to include_domains you trust

This page as Markdown · llms.txt