[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-116848":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":13,"contributorsCount":14,"subscribersCount":14,"size":14,"stars1d":15,"stars7d":16,"stars30d":16,"stars90d":14,"forks30d":14,"starsTrendScore":17,"compositeScore":18,"rankGlobal":9,"rankLanguage":9,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":20,"hasPages":20,"topics":22,"createdAt":9,"pushedAt":29,"updatedAt":30,"readmeContent":31,"aiSummary":9,"trendingCount":14,"starSnapshotCount":14,"syncStatus":32,"lastSyncTime":33,"discoverSource":34},116848,"renfe-cli","luisgonzaleznf\u002Frenfe-cli","luisgonzaleznf","JSON-first CLI for Renfe train timetables and fares. No account needed.",null,"Python",118,5,1,0,9,33,51,80.13,"MIT License",false,"main",[23,24,25,26,27,28],"cli","json","python","renfe","spain","trains","2026-11-21 23:58:25","2026-11-23 14:43:19","# renfe-cli\n\n[![CI](https:\u002F\u002Fgithub.com\u002Fluisgonzaleznf\u002Frenfe-cli\u002Factions\u002Fworkflows\u002Fci.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fluisgonzaleznf\u002Frenfe-cli\u002Factions\u002Fworkflows\u002Fci.yml)\n[![License: MIT](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-MIT-blue.svg)](LICENSE)\n[![Python 3.12+](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpython-3.12%2B-blue.svg)](pyproject.toml)\n\nSearch Renfe trains and fares, and follow live delays, from the terminal. Every command prints JSON, so\nscripts and AI agents can use it as easily as people. No account, no API key, and no browser to search.\n\n> **Unofficial.** Not affiliated with, endorsed by or supported by Renfe. The CLI talks directly to\n> Renfe's own web API, the same anonymous way the website does before anyone signs in. That API is\n> undocumented and can change without notice.\n\n## Features\n\n- **Trains and fares** for a route and date, up to a year ahead: times, duration, changes and every fare\n  for one adult, cheapest first. For trips before 25 Jan 2027 it asks Renfe's legacy shop as a guest, so\n  no train is missing.\n- **Live delays** from Renfe's public train map: one train (`status`), a JSON line whenever it changes\n  (`watch`), or every delayed train on the network with its scheduled times (`delays`).\n- **The number on your ticket works.** A train can run under another number for part of its route;\n  `search`, `status`, `watch` and `delays` find the live train either way.\n- **About 1,400 stations ship with the CLI**, matched by name (accents and case ignored) or code, with\n  spelling suggestions for a typo.\n- **Buy on Renfe's website.** `renfe open` opens the right shop with the route filled in.\n- **Gentle with Renfe.** It sends the requests the website sends, under its own name, starts at most one\n  search a second on a machine, retries only one-off failures, and stops when Renfe blocks it.\n\n## Install\n\nYou need Python 3.12 or later and [uv](https:\u002F\u002Fdocs.astral.sh\u002Fuv\u002F).\n\n```sh\nuv tool install git+https:\u002F\u002Fgithub.com\u002Fluisgonzaleznf\u002Frenfe-cli\nrenfe --help\n```\n\nIt isn't on PyPI yet. The `renfe-cli` package on PyPI is a different project, so `pip install renfe-cli`\nwon't install this one.\n\n## Quick start\n\n```sh\nrenfe stations sevilla                                   # find a station or its code\nrenfe search Madrid Barcelona --date 2027-01-29\nrenfe search Atocha Sants -d tomorrow --after 17:00 --arrive-by 22:00 --limit 5\nrenfe search MADRI BARCE -d 2027-02-05 --no-fares        # timetable only\nrenfe open Madrid Barcelona -d 2027-01-29 --train 03081  # buy it on Renfe's website\nrenfe delays                                             # delayed trains, with scheduled endpoint times\nrenfe delays 37432                                       # a delayed train using this number on any verified section\nrenfe status 03081                                       # that train's live delay and next station\nrenfe watch 03081                                        # a JSON line each time that changes\n```\n\nA search prints one JSON document. This one ran on 19 Nov 2026 with `--after 08:00 --limit 2`; the second\ntrain is left out here:\n\n```json\n{\n  \"date\": \"2027-01-29\",\n  \"origin\": {\"code\": \"MADRI\", \"name\": \"Madrid (Todas)\", \"province\": \"Madrid\", \"group\": true, \"main\": true},\n  \"destination\": {\"code\": \"BARCE\", \"name\": \"Barcelona (Todas)\", \"province\": \"Barcelona\", \"group\": true, \"main\": true},\n  \"passengers\": {\"adults\": 1},\n  \"fares_included\": true,\n  \"notice\": null,\n  \"count\": 2,\n  \"trains\": [\n    {\n      \"service\": \"03091\",\n      \"type\": \"AVE\",\n      \"type_code\": \"AV1\",\n      \"departure\": \"2027-01-29T08:57:00+01:00\",\n      \"arrival\": \"2027-01-29T12:06:00+01:00\",\n      \"duration_minutes\": 189,\n      \"changes\": 0,\n      \"available\": true,\n      \"fares\": [\n        {\"name\": \"Básico\", \"price\": 44.07, \"currency\": \"EUR\"},\n        {\"name\": \"Elige\", \"price\": 48.48, \"currency\": \"EUR\"},\n        {\"name\": \"Elige Confort\", \"price\": 52.77, \"currency\": \"EUR\"},\n        {\"name\": \"Premium\", \"price\": 71.77, \"currency\": \"EUR\"}\n      ],\n      \"intermediate_stops\": 1,\n      \"delay_minutes\": null,\n      \"live_train\": null\n    }\n  ],\n  \"shop\": {\n    \"url\": \"https:\u002F\u002Fventa.rsv.renfe.com\u002Fcoext\u002Fsearch?originUicStationCode=MADRI&destinationUicStationCode=BARCE&isOneWay=true\",\n    \"prefilled\": [\"origin\", \"destination\", \"one_way\"],\n    \"next\": \"Pick 2027-01-29 as the date (Renfe's new shop doesn't take one in a link), press 'Buscar billetes' and pick your train.\"\n  },\n  \"delays_included\": false,\n  \"retries\": []\n}\n```\n\nSo it pipes straight into other tools:\n\n```sh\nrenfe search Madrid Barcelona -d 2027-01-29 --after 08:00 --limit 2 \\\n  | jq -r '.trains[] | \"\\(.departure[11:16]) \\(.service) \\(.type) from \\(.fares[0].price) €\"'\n# 08:57 03091 AVE from 44.07 €\n# 09:27 03093 AVE from 49.8 €\n```\n\n## Commands\n\n| Command | What it does |\n|---|---|\n| `renfe stations [QUERY]` | Stations and city groups matching a name or code, best match first |\n| `renfe search FROM TO` | Trains on a date, with times, changes and fares for one adult; for today, live delays too |\n| `renfe open FROM TO` | Opens Renfe's shop for that search in your browser, or prints the link |\n| `renfe delays [TRAIN]` | Every delayed train on the live map, with its scheduled departure and arrival |\n| `renfe status TRAIN` | One train's live delay, its next station and the expected arrival there |\n| `renfe watch TRAIN` | A JSON line each time that train's live status changes |\n\nEvery command has `--help`. stdout is always JSON (JSON Lines for `watch`), and errors go to stderr with\nthe exit codes in [Output and errors](#output-and-errors).\n\n## Searching\n\n`search` returns, for each train:\n- service number and `type_code`, plus `type` (AVE, Intercity…) when fares are fetched; a train\n  with a change gets one name per leg, as on the website (`INTERCITY + INTERCITY`). Before 25 Jan 2027\n  `type` is always there and `type_code` is `null`;\n- departure and arrival in each station's local time, as Renfe reports it;\n- duration and number of changes;\n- fares for one adult, cheapest first;\n- `delay_minutes`: for today, the train's live delay, else `null`. A train with a change also has one on\n  each leg, and the train's is the first of those the map has. Beside it, `live_train` is the number on the\n  live map that delay came from (`null` with no delay): the train's own, or a published partner's when the\n  number you'd buy isn't on the map (see [Delays](#delays)).\n\nIt also returns `retries`, empty when nothing was retried: one entry per request that failed once and was\ntried again, with `request` (which one), `tries`, `errors` (what failed on each try, such as\n`server error (500)` or `connection dropped (RemoteProtocolError)`) and `recovered` (whether a later try\nworked). A retry that worked isn't a problem with the list, so it never goes into `notice`. A request the\nsearch stopped waiting for (the live map, see [Delays](#delays)) ends with an error saying so. When a\ncommand fails after retries, the stderr error object carries the same `retries` list.\n\nIt also returns `shop`: the page on Renfe's website where that search continues, to pick the train and\npay.\n\nDates are YYYY-MM-DD, `today` or `tomorrow`, up to a year ahead. `search` returns at most 10 trains by default\n(`--limit`, up to 200). Fares cost one extra request per 3\ntrains. For today, trains that have already left are hidden unless you pass `--after`; before 25 Jan 2027\nthe legacy shop can leave them out anyway (see [Delays](#delays)).\n\n`--arrive-by HH:MM` keeps journeys scheduled to reach the destination by that time on the search date\n(Madrid time). An arrival exactly at the deadline qualifies. An arrival after midnight the next day falls\noutside the window. The filter applies before `--limit` and fare requests.\n\n### Stations\n\nStations are matched by name, ignoring accents and case, or by code. A city name such as `Madrid` means\nall of that city's stations (`MADRI`). Renfe's list of about 1,400 stations ships with the CLI, so\nfinding one sends no request. Only a name that matches none of them makes the CLI ask Renfe for its\ncurrent list, in case the station is newer than the shipped one; that list is kept for a day.\nIf neither list matches, `stations` returns up to five spelling suggestions from the shipped list.\nFor example, `renfe stations Chamartn` suggests Madrid-Chamartín. Use its code or corrected name to search.\n`renfe stations --refresh` asks Renfe directly. The cache folder is `~\u002F.cache\u002Frenfe-cli`, or\n`$XDG_CACHE_HOME\u002Frenfe-cli`, or `$RENFE_CACHE_DIR` if set.\n\n### Before 25 Jan 2027: Renfe's legacy shop\n\nRenfe is moving to a new sales system, which prices trips\nonly from 25 Jan 2027 and before that knows only some trains (for Madrid–Barcelona on Friday 20 Nov 2026,\n8 of the 24). Renfe sells the earlier trips on its legacy shop (venta.renfe.com), so for those dates\n`search` asks the legacy shop, the way its results page does, and gets every train with its fares in the\nsame JSON (Madrid–Barcelona on Friday 27 Nov 2026, checked 2026-11-17: 24 trains, cheapest €31.15).\nThere, `type_code` and `intermediate_stops` are `null`, and a train that isn't on sale (full, \"not on\nsale at the moment\", not running, or only wheelchair places left) has `available: false` and no fares.\n`renfe search` only reads the list. Buy on Renfe's site with `renfe open`.\n\nA one-off failure at any of the legacy shop's four requests (a 500 or 502 without `Retry-After`, whatever\nits body, or a dropped connection) starts its search over from the first request, with a new guest session\nand fresh cookies, up to 3 tries in all. A request there that gets no answer for 12 s starts the search over\nonce more, not twice (on 19 Nov one train list hung for the CLI's general 25 s while the shop answered other\nsearches in about a second; over two days the slowest search that got its list took 11.9 s for the whole\ncommand).\nA 503 or 504 there isn't retried: it may be an edge deny or a\nwaiting room. If it still fails (or a block or rate limit, a waiting room or challenge page, or an answer\nthe CLI can't read stops it), or it lists no trains, you get the new system's partial list instead, without\nfares, and a `notice` saying what failed; the exit code stays 0. On 19 Nov 2026 the legacy shop sent no train\nlist at all for any search from 03:49 until 04:04 (Madrid–Barcelona) and about 04:35 (Zaragoza–Madrid); the\nnotice then says it \"isn't listing trains right now\". The one exception is today at the end of the day:\nthe legacy shop lists only trains leaving in more than about 5 minutes (see [Delays](#delays)), so when it\nlists none and the new system has nothing leaving later either, nothing failed. With no train left, the only\nnotice is \"No more trains today\". With the last trains leaving within those minutes, the list shows them from\nthe new system, without fares, and the notice says the legacy shop no longer lists them.\nOn any other date (or judged by `--after`), an empty list from the legacy shop keeps the fallback notice:\nbefore 25 Jan the new system lists only part of the timetable, so its being empty too proves little. The\nCLI never tries to get past a waiting room or a captcha. `shop.url` and `renfe open` take you to the full\nlist on Renfe's website either way.\n\nFrom 25 Jan 2027 the CLI's list matches the website's exactly, trains and cheapest fares (checked\nagainst the web for Friday 29 Jan: 22 trains each).\n\n### Requests, speed and retries\n\nEvery request names the CLI in its User-Agent (`renfe-cli\u002F` and the version) instead of posing as a\nbrowser, so Renfe can tell what it is. Searches are spaced: on one machine at most one starts per second,\nacross every `renfe` process, so a script or an agent running them in a loop can't burst; a single search's\nown requests aren't slowed. The CLI sends what the website sends, no more: one timetable call, then fares 3 trains per call with at most 3 calls in\nflight; before 25 Jan 2027, the four requests the legacy shop's results page makes. If Renfe blocks\nor rate-limits it, it stops and says so (exit 5); before 25 Jan 2027 it falls back instead (see\n[above](#before-25-jan-2027-renfes-legacy-shop)). What it retries: a one-off failure (a 500, 502, 503 or 504 with a JSON or empty body, or a\nconnection that drops or is refused), up to 3 tries per request, 1 s and 2 s apart, listed in the\noutput's `retries`; one of those 3 tries can be the resend when Renfe rejects a saved session with 401\n(see below). An HTML page at any status is taken for bot protection and tried once; so are a block, a\nrate limit and a timeout. The legacy shop has its own rule (above).\nLive delays come from Renfe's public live train map. The network-wide\n`delays` command also downloads Renfe's public timetable when it needs to look up scheduled times.\n\nSpeed (measured 2026-11-15): a search takes about 0.3–0.5 s, and a full day of 22 trains with fares\nabout 1.4 s. The anonymous session (a 30-minute token and the site's public API key) is kept in the\ncache folder as `session.json`, so a timetable search usually sends a single request; fares add one per\n3 trains. If Renfe answers 401 to a saved session, the CLI opens a new one and resends that request\nonce. A 403 is reported as a block, and the saved session is dropped so the next run starts afresh. A\n500, 502, 503 or 504, or a dropped or refused connection, is tried up to 3 times, 1 s and then 2 s apart\n(a 24-hour soak test on 18 Nov saw single requests fail like that and work again a minute later). The\n401 resend counts as one of those 3 tries and goes at once; a retry after it waits 1 s, as a first retry\ndoes, and a 403 to a saved session drops the file even on the third try. An HTML page is bot protection\nwhatever its status (a 503 page too), and isn't retried. Neither is a timeout: one already costs the whole\n25 s timeout (the legacy shop's is 12 s, and tried once more; see above). With no network at all, a search takes a few seconds longer to fail than before (3 s of\npauses; 6 s before 25 Jan 2027, when the legacy shop is tried first), since a DNS or TLS failure counts as a\nrefused connection.\nBefore 25 Jan 2027 a search is the legacy shop's four requests instead, about 0.8–1.8 s with fares\n(measured 2026-11-17), and nothing is saved: its cookies live in memory for that one search. A search for\ntoday also sends one request to Renfe's live map, alongside the others (see [Delays](#delays)).\n\n## Buying\n\n`renfe open FROM TO -d DATE` opens that page in your browser when run from a terminal\n(`--browser` forces it, `--no-browser` only prints the link). Add `--train` to check the train exists\nthat day and show it, so you know which one to pick. With `open`, you pick the train and pay on Renfe’s page.\n- **Dates before 25 Jan 2027:** www.renfe.com opens with the route and the date filled in. Mark\n  \"Solo ida\" (or pick a return date) to enable \"Buscar billetes\"; it then searches Renfe's legacy shop.\n- **From 25 Jan 2027:** Renfe's new shop opens with the route filled in and one way selected. Pick the\n  date there: the new shop doesn't take a date in a link.\n- `--train` is checked against the full list (before 25 Jan 2027, the legacy shop's). If the legacy shop\n  fails, the CLI sees only the new system's partial list, so a train it can't see still opens the page,\n  with a `notice`.\n\n## Delays\n\n`renfe delays` lists every train reporting a positive delay on Renfe's live long- and medium-distance\nmap, most delayed first. Each entry in `trains` includes `delay_minutes`, the `origin` and\n`destination`, and the times the train was due to **leave its origin** (`scheduled_departure`)\nand **reach its destination** (`scheduled_arrival`). Both times include the local date and Madrid\nUTC offset. The live prediction for the next stop is a separate field, `next_station.expected_arrival`.\n`map_updated` dates the snapshot. The counts `delayed`, `on_time`, `early`, and `unknown` add up\nto `mapped_trains`, including when the map is empty.\n\nThe command fetches one map for the whole report and looks up all the schedules in a single public GTFS\ntimetable, cached for 24 hours. Any retried requests appear in the top-level `retries` list.\nIt checks the service calendar, including dated exceptions, and\nuses the reported delay and live time to identify the run around midnight. [Renfe's timetable](https:\u002F\u002Fdata.renfe.com\u002Fes\u002Fdataset\u002Fhorarios-de-alta-velocidad-larga-distancia-y-media-distancia)\n\n**Looking up the number on a ticket.** `renfe delays TRAIN` returns every delayed train whose live\nnumber or verified section matches. Leading zeros are optional. `train` is the number on the live map.\nEach entry in `number_segments` gives a train number, its origin and destination stations, and its\nscheduled departure and arrival for that stretch. A single train still counts once. On November 18,\nfor example, `00632` ran from Zaragoza to Salamanca. `37632` covered Miranda de Ebro to Valladolid,\nand `37432` covered Valladolid to Salamanca. All three searches returned the same live report.\nThe network totals still cover the whole map. `matched_trains` counts the rows returned by the filter.\n`schedule_matches` counts exact, linked, ambiguous, unmatched and unavailable schedules among the\nreturned rows. Add `exact` and `linked` to get the number with scheduled departure and arrival times.\n\nRenfe's published groupings supply candidate numbers. The CLI checks active services on the run date,\nincluding when a train arrives after midnight. A shared stretch must have matching stations, direction\nand times. To join successive legs it also checks the published journey endpoints and how the legs\nmeet. A number missing from the published list or lacking timetable evidence can be absent from\n`number_segments`. An unresolved schedule has an empty list. [Renfe's published train-number groups](https:\u002F\u002Fgrupo.renfe.com\u002Fcontent\u002Fdam\u002Fgrupo-renfe\u002Fsala-de-prensa\u002Fsala-de-prensa\u002Fgeneral\u002Fpdf-y-otros\u002FTrenes%2017%20noviembre%20SC.pdf)\n\n- `schedule_match: exact` means the train number and both stations match one set of scheduled times.\n- `linked` means matching the journey required another published number. `schedule_trains` lists\n  the verified numbers and `number_segments` shows where each applies.\n- `unmatched` means no schedule fit. `ambiguous` means several different times fit. In both cases\n  the train stays in the list with both scheduled times set to `null`.\n- If the timetable fails, `schedule_match` is `unavailable` and the top-level `notice` explains why.\n  The live report still exits successfully. If the live map itself fails, the command reports an error.\n\n`renfe status TRAIN` shows a train's live delay from Renfe's live train map, the public JSON behind its map\npage (`tiempo-real.largorecorrido.renfe.com`, no key or session). TRAIN is a number from `renfe search`\n(`03081`, leading zeros optional); for a train with a change, one leg's number. It returns\n`delay_minutes` (negative: early), the train's origin and destination, its previous and next station (with\nthe expected arrival there), `overdue`, `reported_at`, `map_updated` and `retries` (as in `search`, for the\nmap or timetable request). `reported_at` is the time on the\ntrain's entry; Renfe refreshes it every few minutes even when the entry's delay and stations are hours old,\nso it doesn't show how fresh they are.\n\nEvery status includes `requested_train`, `scheduled_departure`, `scheduled_arrival`, `schedule_match` and\n`number_segments`. A direct map hit takes priority and uses the same timetable matching as `delays`. If\nthe timetable fails, the live result still prints with `schedule_match: \"unavailable\"` and the reason in\n`notice`. Unknown times are null and unknown sections are an empty array.\n\nWhen a ticket number is absent from the map but a published partner number is present, `renfe status TRAIN`\nchecks the timetable for a matching section. A unique match includes the ticket number in `requested_train`\nand the live number in `train`, including for early and on-time trains. When several live trains match,\n`matching_trains` lists them and the delay is unknown.\n\n- **While it runs, and mainly long- and medium-distance trains.** The map lists trains around the time they\n  run (some while still at their first station), and at night it is empty. A train that isn't on it has\n  `on_map: false` and no delay: it may not have left yet, may have arrived or been cancelled, or isn't on\n  the map at all. Its delay is unknown, not zero.\n- **The delay is the last one Renfe recorded.** A train held somewhere keeps its delay and next station\n  while it gets later. `overdue` is `true` once the expected arrival at its next station is more than 5\n  minutes behind the map's update, or more than 10 when Renfe gives the same station as previous and next\n  (the train is probably stopped there, and the notice says since when); never while the train runs early,\n  waiting for its time. After midnight the map can date that arrival a day ahead; `status` brings it back.\n- **Whichever run is on the map.** The map has no run date, so after midnight `status` and `watch` can show\n  yesterday's run of a train that runs again today, still going (on 18 Nov at 02:14, 18135 of the 17th, 170\n  minutes late). `delays` looks up the service day for that run. `search` checks whether the entry\n  fits the requested journey (below).\n- **Unreachable at times.** On 17 Nov 2026 it refused connections from Spain for over two hours while it\n  answered from other countries. On 18 Nov, checked every 15 minutes from 12:24 to 22:04, it answered every\n  time but once, when it dropped connections for under a minute (4 requests failed over about 10 seconds,\n  and one a minute later worked). A refused or dropped connection, or a 500, 502, 503 or 504 that isn't an\n  HTML page, is tried up to 3 times (listed in `retries`); an HTML page is taken for bot protection and\n  tried once. `status` fails with exit 5 when it still fails, or when the\n  map doesn't connect or send data for 10 s at a time (a timeout isn't retried).\n\n**In `search`, for today only.** The search asks the map alongside its own requests and waits for it at most\n2.5 s from its start, so a map that hangs costs at most that. Only when a train on the list isn't on the map\nunder its number but a published partner number is, it then waits at most 3 s more for Renfe's timetable\n(below). It retries the map only when the pause and\nanother try can end within those 2.5 s; a retry still running when the search stops waiting is listed in\n`retries` as not recovered. Each train on the map gets its\n`delay_minutes`, the last one recorded, as in `status`; one that isn't gets `null`, and so do they all on\nother days. `delays_included` says whether the map answered: when it doesn't, `notice` says the delays are\nunknown, and the search and its exit code are unaffected. A train gets no delay from an entry left over on\nthe map: one whose expected arrival at its next station is more than 45 minutes past (on 17 Nov at 17:48,\n4 of 95, one of them still at its first station 7.5 hours later with a delay of 0). Nor from yesterday's\nrun: the map's time for the train must be less than 12 hours before the leg searched leaves or after it\narrives. `renfe open` never asks the map.\n\nA train sold under one number can run on the map under another, as `renfe status` explains for ticket numbers.\nThen the search checks Renfe's timetable the way `status` does, loading it at most once (it is cached for a day)\nand in one try. The leg gets the live train's delay, with that number in `live_train`, only when a verified\nsection under the leg's number spans the leg's scheduled times, and the same checks as above pass. So a\ndelay the search attaches is the live train and delay `renfe status NUMBER` gives (`status` also shows an\nentry left over on the map, which the search drops). If the timetable fails or takes longer than 3 s, those\nlegs keep `null` and the notice says \"Delays of trains sold under another number are unknown\", with the\nreason. With no cached timetable on a slow connection, a search that stops waiting leaves the cache empty, so\nthe next one waits again; `renfe delays` or `renfe status` fills it. On 18–20 Nov 2026, on the two routes the\nsoak test searched (Madrid–Barcelona, Zaragoza–Madrid), a sold number was off the map while a published\npartner was on it once in 347 searches; routes with more partner numbers see it more often.\n\nToday's list hides trains past their scheduled departure, even a late one that hasn't reached your station\nyet:\n- **Before 25 Jan 2027** the list comes from the legacy shop, which stops listing a train about 5 minutes\n  before it leaves the station searched from, even with `--after`. Checked every 15 minutes on two routes on\n  18–20 Nov 2026: of 74 trains due within 15 minutes, the 6 due in under 5 minutes were missing and the 68\n  due in 5.8 minutes or more were there. On 18 Nov 2026 at about 06:30, `search Barcelona Madrid\n  --after 05:00` started at 06:35, without 03052, which had left Barcelona-Sants (its first station) at\n  05:40 and was on the map 7 minutes late. From a station further along its route, without `--after`, it\n  was there: `search Zaragoza Madrid` listed it leaving at 07:09, with `delay_minutes: 7`.\n- **From 25 Jan 2027** `--after HH:MM` shows the trains Renfe's new system lists for that time; whether it\n  lists trains that have already left is unverified.\n\n**`renfe watch TRAIN`** checks the map every 2 minutes and prints one line of JSON, shaped like `status`'s\noutput, on the first check and whenever the train's delay, its next station, the expected arrival there,\n`overdue` or `on_map` changes, by any amount. Renfe moves the expected arrival between delay updates, so it\nis the finer signal: on 18 Nov from 06:29 to 06:59 it moved 264 times with the delay and next station\nunchanged, mostly by a minute either way, and a train on the map throughout gave about 10 lines in those\n30 minutes (at most 15). It keeps checking a train that isn't on the map yet, so you can start it before\ndeparture. A ticket number works too. When a published partner appears, the watch verifies its section\nagainst the timetable. Several matches produce a line listing `matching_trains`. Once one partner matches,\nthe watch follows it even if another partner appears later. If the exact number you requested appears, the\nwatch prints its status and follows that number for the rest of the watch.\n\nThe watch loads the timetable at most once. If that load fails during ticket lookup, one line gives the\nreason. The watch can still follow the exact number on the map, but it cannot match the ticket to a partner\nfor the rest of that watch. Status lines carry the same schedule fields as `renfe status`. Event lines\ninclude `requested_train` only while the watch is following a different live number.\n\nEach status line has that check's `retries`, which don't count as a change. Two other lines carry an\n`event` instead: `map_unreachable` (with the `error` and `retries`) when the map stops answering, after its\nretries, once per outage, after which the next answer prints a line whether or not anything changed; and\n`ended` when the watch stops on its own. Pipe it into whatever pings you; the CLI sends no notifications\nitself:\n\n```sh\nrenfe watch 03081 | while read -r line; do\n  case \"$line\" in\n    *'\"event\": \"map_unreachable\"'*) msg=\"Renfe's live map isn't answering: delay unknown for now\" ;;\n    *'\"event\": \"ended\"'*) msg=\"renfe watch has stopped\" ;;\n    *) msg=\"$line\" ;;\n  esac\n  curl -s -d \"$msg\" https:\u002F\u002Fntfy.sh\u002F\u003Cyour-topic> >\u002Fdev\u002Fnull\ndone\n```\n\n- It ends on its own after 12 hours (the map doesn't show where a trip ends; for a longer one, run it\n  again), or on Ctrl-C, both with exit 0. If what reads its output goes away, it ends with exit 1.\n- A map that doesn't answer doesn't end it. A block or rate limit (403\u002F429, a bot page) stops it with exit 5,\n  and 3 answers in a row that aren't the map (it moved or changed) with exit 7.\n- A train held somewhere keeps its delay, its next station and the expected arrival there, which slips into\n  the past. `watch` prints one line when it becomes overdue there, and another when it moves on or Renfe\n  updates it, not one per check.\n\n## Output and errors\n\nstdout is one JSON document, except for `watch`, which prints one per line (JSON Lines, including its outage\nlines). Errors go to stderr as `{\"error\": {...}}`, with these exit codes:\n\n| Code | Meaning |\n|---|---|\n| `0` | ok; check `notice` |\n| `1` | internal error (only the exception type is shown) |\n| `2` | usage: bad arguments, unknown station, bad date, or a request Renfe rejected |\n| `3` | auth: Renfe refused the anonymous session |\n| `5` | blocked or upstream: 403\u002F429, a bot page, timeout or 5xx, including Renfe's live map for `delays` and `status` (for `watch`, only a block or rate limit). If this happens while fetching fares, stdout still has the timetable (plus `fares_error`). On the legacy shop it falls back instead (exit 0, `notice`) |\n| `7` | API changed |\n\n## Contributing\n\nIssues and pull requests are welcome. To work on the code:\n\n```sh\ngit clone https:\u002F\u002Fgithub.com\u002Fluisgonzaleznf\u002Frenfe-cli\ncd renfe-cli\nuv sync\npython3 .githooks\u002Fpii_check.py enable   # once per clone: the personal-data guard (below)\nuv run renfe --help                     # your working copy\nuv run pytest                           # offline: HTTP is mocked\nRENFE_LIVE=1 uv run pytest -m live      # about 10 real requests, plus one to the live map\nuv run python scripts\u002Fupdate_stations.py  # refresh the shipped station list; prints what changed\n```\n\n- Keep tests offline: HTTP is mocked. A test that calls Renfe gets the `live` marker, so it runs only with\n  `RENFE_LIVE=1`.\n- Scripts and agents read the output, so add JSON fields rather than renaming or removing them.\n- Never commit real passenger or booking data, captures (HAR files), tickets or tokens. Use obviously fake\n  values in tests.\n\nCI runs the offline suite on Linux and macOS, with Python 3.12 and 3.13, for every pull request.\n\nA scheduled workflow (`.github\u002Fworkflows\u002Fstations-reminder.yml`) opens an issue to refresh the station\nlist on 1 February and 1 August. GitHub turns schedules off in a public repo after 60 days without\nactivity; re-enable it from the Actions tab, or run it from there by hand.\n\nPersonal-data guard: `.githooks\u002F` checks staged changes and commit messages for passengers' and\nbuyers' data (names, DNI\u002FNIE, emails, phones, booking locators, card numbers) and for capture files.\nEnable it once per clone with `python3 .githooks\u002Fpii_check.py enable`.\n\n## License\n\n[MIT](LICENSE). The station list and train-number groups in `src\u002Frenfe\u002Fdata\u002F` come from Renfe's own\ndata and aren't covered by the MIT license. The station list is the one Renfe's web app loads (its station\nmaster data), refreshed with `scripts\u002Fupdate_stations.py`. Renfe is a trademark of its owner; this project\nuses the name only to say which service it works with.\n\nIf Renfe objects to anything this project does, open an issue, and that part will change or come out.\n",2,"2026-11-24 04:54:22","CREATED_QUERY"]