# Watch

Poll a page and get only the links you haven't seen before.

`watch` reads a listing, feed or search page and returns the same-site links
that are new since your last poll. You decide when to poll and what a link
means.

- Filter links with a regular expression.
- The first poll returns every current link and sets `first_poll`, so you can
  treat it as a baseline.
- Each poll is one ordinary read: paced, receipted, and able to climb past
  walls.

## Many sites: `watch_sites`

To keep up with many sites at once, `watch_sites` uses what each site
publishes about its own new pages instead of reading its front page:

- the feeds it advertises (`<link rel="alternate">`: RSS, Atom, JSON Feed);
- the sitemaps `robots.txt` names (news sitemaps first, then the most recently
  changed);
- a few conventional feed paths (`/feed`, `/rss.xml`, …) when it advertises none.

They are found once per site and remembered for a week. Every poll fetches
them with conditional requests (`If-None-Match`, `If-Modified-Since`), so an
unchanged feed costs one small 304. Pages already reported are remembered,
and the same story under two URLs (syndication) is reported once.

```python
new = await web.watch_sites(["https://news.example.com/", "https://blog.example.org/"],
                            since="2026-10-07", read_new=True)
for page in new["pages"]:
    print(page["published"], page["url"], page["quality"])
```

```bash
frankensurf watch-sites https://news.example.com/ https://blog.example.org/ --since 2026-10-07
```

`read_new` reads the new pages too, with main content, as one paced batch.
`requests` and `unchanged_feeds` in the answer say what a poll cost.

## One page: `watch`

## Usage

```python
poll = await web.watch("https://news.ycombinator.com/", link_pattern=r"item\?id=\d+")
for link in poll["new"]:
    print(link["url"])
```

```bash
frankensurf watch https://news.ycombinator.com/ --link-pattern 'item\?id=\d+'
```

```json title="Response (trimmed)"
{
  "url": "https://news.ycombinator.com/",
  "status": "observed",
  "first_poll": true,
  "new": [
    { "url": "https://news.ycombinator.com/item?id=49969183", "text": "4 hours ago" },
    { "url": "https://news.ycombinator.com/item?id=49971230", "text": "1 hour ago" }
  ],
  "links_on_page": 30,
  "seen_count": 30,
  "receipt": { "status": "observed", "method": "http" }
}
```

## Options

| Option | Default | Description |
| --- | --- | --- |
| `link_pattern` | all same-site links | Regular expression a link URL must match. |
| `state_key` | the URL | Name of the watch, if you watch one URL several ways. |
| `max_seen` | `5000` | Links remembered per watch. |

Seen links are stored under `<state>/watches/`.

  A few polls an hour is plenty for most pages. Pacing and cool-downs apply, so
  hammering a page only gets it paused.
