Menu

Guides

News monitoring

Watch a subject in the news and be told only about what is new. With a scheduled search, or more simply with Monitor.

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

The job: for a subject you care about, learn about new articles soon after they appear, and never be told about the same one twice. The first half of this guide does it with the Search API and your own scheduler; the second half lets a Monitor do the remembering.

Run a news search on a schedule and remember the URLs you have already seen. Every news result carries a published_date, so start_date leaves out anything old, and exclude_risky leaves out sites that carry a risk label.

Example
Python
import json
import os
import pathlib
from datetime import date, timedelta

from millionshort import MillionShort

client = MillionShort(api_key=os.environ["MILLIONSHORT_API_KEY"])

QUERY = "central bank interest rate decision"
STATE = pathlib.Path("seen-urls.json")


def check():
    seen = set(json.loads(STATE.read_text())) if STATE.exists() else set()
    since = (date.today() - timedelta(days=3)).isoformat()
    r = client.search(QUERY, sources=["news"], num_results=20, start_date=since, exclude_risky=True)
    fresh = [hit for hit in r.results if hit["url"] not in seen]
    STATE.write_text(json.dumps(sorted(seen | {hit["url"] for hit in r.results})))
    return fresh, r.usage.credits


fresh, credits = check()
for hit in fresh:
    print(hit["published_date"], hit["extra"].get("publisher"), hit["title"], hit["url"])
print(len(fresh), "new;", credits, "credits")

Run it from a scheduler of your choice, once an hour. The first run reports everything recent; later runs report only what is new.

Make it better:

What it costs: one search of news with 20 results is 1.5 credits. Hourly, that is 36 credits a day, about $0.04.

With Monitor

A query monitor does the remembering for you. It runs the search on an interval and produces an event only when a result URL appears that it has not seen before. On news the shortest interval is one hour; on social and hn it is 15 minutes.

Create it once:

Example
Shell
curl https://api.millionshort.com/v1/monitors \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "query",
    "name": "rate decisions",
    "query": "central bank interest rate decision",
    "source": "news",
    "top_n": 20,
    "interval_minutes": 60
  }'

Then either pull its events when it suits you:

Example
Shell
curl "https://api.millionshort.com/v1/monitors/$MONITOR_ID/events?limit=50" \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY"

or register a webhook and have each monitor.changed event delivered, signed, to your own endpoint. The event's data.new_results holds the new articles, with title, url, site, snippet and published_date.

Each check costs 1 credit, and a check that fails is free. An hourly monitor is 24 credits a day.

Watching a page

News does not always arrive as an article. To watch one page, a press room or a regulator's notices, a url monitor reports when the page's text changes and shows what was added and removed. See Monitor parameters.

This page as Markdown · llms.txt