renfe-cli icon indicating copy to clipboard operation
renfe-cli copied to clipboard

renfe web scraped not available

Open astrojuanlu opened this issue 1 year ago • 3 comments

❯ .venv/bin/python -V
Python 3.12.3
❯ uv pip freeze | grep renfe-cli
renfe-cli==4.3.1
❯ RUST_BACKTRACE=1 uv run renfe-cli -f "Madrid (ALL)" -t "Vigo (ALL)"
warning: `uv run` is experimental and may change without warning
Loading stations from Renfe web
Provided input 'Madrid (ALL)' station matches with 'Madrid (ALL) '...continue
Provided input 'Vigo (ALL)' station matches with 'Vigo (ALL)'...continue
Today is: 2024-8-15
Searching timetable for date: 2024-8-15
loading headless chrome browser
navigating to renfe timetable search page
waiting for search page
adding origin station
adding destination station
adding day
adding month
adding year
searching timetable
got timetable page
wait for timetable iframe
thread '<unnamed>' panicked at src/timetable.rs:166:10:
called `Result::unwrap()` on an `Err` value: Method call error -32000: Invalid search result range

Stack backtrace:
   0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
   1: headless_chrome::types::parse_response
   2: headless_chrome::browser::transport::Transport::call_method
   3: headless_chrome::browser::tab::Tab::call_method
   4: headless_chrome::browser::tab::Tab::find_elements_by_xpath
   5: headless_chrome::util::Wait::strict_until
   6: headless_chrome::browser::tab::Tab::wait_for_elements_by_xpath
   7: renfe_cli::timetable::search_timetable
   8: renfe_cli::cli::<impl renfe_cli::cli::main::MakeDef>::DEF::trampoline
   9: <unknown>
  10: PyObject_Vectorcall
  11: _PyEval_EvalFrameDefault
  12: PyEval_EvalCode
  13: <unknown>
  14: <unknown>
  15: _PyRun_SimpleFileObject
  16: _PyRun_AnyFileObject
  17: Py_RunMain
  18: Py_BytesMain
  19: __libc_start_call_main
             at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  20: __libc_start_main_impl
             at ./csu/../csu/libc-start.c:360:3
  21: _start
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/panicking.rs:647:5
   1: core::panicking::panic_fmt
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/core/src/result.rs:1649:5
   3: renfe_cli::timetable::search_timetable
   4: renfe_cli::cli::<impl renfe_cli::cli::main::MakeDef>::DEF::trampoline
   5: <unknown>
   6: PyObject_Vectorcall
   7: _PyEval_EvalFrameDefault
   8: PyEval_EvalCode
   9: <unknown>
  10: <unknown>
  11: _PyRun_SimpleFileObject
  12: _PyRun_AnyFileObject
  13: Py_RunMain
  14: Py_BytesMain
  15: __libc_start_call_main
             at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  16: __libc_start_main_impl
             at ./csu/../csu/libc-start.c:360:3
  17: _start
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Traceback (most recent call last):
  File "/tmp/renfe-playground/.venv/bin/renfe-cli", line 8, in <module>
    sys.exit(main())
             ^^^^^^
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: Method call error -32000: Invalid search result range

Stack backtrace:
   0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
   1: headless_chrome::types::parse_response
   2: headless_chrome::browser::transport::Transport::call_method
   3: headless_chrome::browser::tab::Tab::call_method
   4: headless_chrome::browser::tab::Tab::find_elements_by_xpath
   5: headless_chrome::util::Wait::strict_until
   6: headless_chrome::browser::tab::Tab::wait_for_elements_by_xpath
   7: renfe_cli::timetable::search_timetable
   8: renfe_cli::cli::<impl renfe_cli::cli::main::MakeDef>::DEF::trampoline
   9: <unknown>
  10: PyObject_Vectorcall
  11: _PyEval_EvalFrameDefault
  12: PyEval_EvalCode
  13: <unknown>
  14: <unknown>
  15: _PyRun_SimpleFileObject
  16: _PyRun_AnyFileObject
  17: Py_RunMain
  18: Py_BytesMain
  19: __libc_start_call_main
             at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  20: __libc_start_main_impl
             at ./csu/../csu/libc-start.c:360:3
  21: _start

(thank you for the initiative by the way! 🙌🏼)

astrojuanlu avatar Aug 15 '24 11:08 astrojuanlu

Bueno alomojó tiene que ver con esto 😂

image

astrojuanlu avatar Aug 15 '24 11:08 astrojuanlu

hola @astrojuanlu , correcto, renfe web es lo peor para poder hacer algun scrapping, me temo que el proyecto ha quedado congelado debido a esto que muestras, pero tenemos algunas opciones: 1- rehacer el scraping con la estratègia actual (a lo cual no veo futuro, ya que la web de renfe no es estable) 2- usar otras APIs existentes (que por ahora no he encontrado) 3- descarga y parseo de los datasets que comenta @gtrabanco en https://github.com/gerardcl/renfe-cli/issues/194 o seguir explorando via ADIF...

gerardcl avatar Aug 31 '24 12:08 gerardcl

hola @astrojuanlu , correcto, renfe web es lo peor para poder hacer algun scrapping, me temo que el proyecto ha quedado congelado debido a esto que muestras, pero tenemos algunas opciones: 1- rehacer el scraping con la estratègia actual (a lo cual no veo futuro, ya que la web de renfe no es estable) 2- usar otras APIs existentes (que por ahora no he encontrado) 3- descarga y parseo de los datasets que comenta @gtrabanco en #194 o seguir explorando via ADIF...

También tienes la opción de https://www.adifaltavelocidad.es en la que además se ven los retrasos en tiempo real, pero no puedes hacer seguimiento de trenes como en la app móvil.

gtrabanco avatar Aug 31 '24 13:08 gtrabanco

hi @gtrabanco and @astrojuanlu , I have been playing with the GTFS files from https://data.renfe.com/dataset/horarios-de-alta-velocidad-larga-distancia-y-media-distancia and here I have a working prototype (to be fine-tuned etc) https://github.com/gerardcl/renfe-cli/commit/91befa433c3f450f550110f97218afce77dce640 <- take a look! :eyes: IMHO we can proceed with this!

example output:

GTFS data:
  Read in 1507 ms
  Stops: 803
  Routes: 636
  Trips: 4515
  Agencies: 1
  Shapes: 0
  Fare attributes: 0
  Feed info: 0
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 05:46:00 - arrival at 06:25:00 - with duration 00:39
Trip AVLO from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 05:46:00 - arrival at 06:25:00 - with duration 00:39
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 06:14:00 - arrival at 07:40:00 - with duration 01:26
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 06:27:00 - arrival at 07:54:00 - with duration 01:27
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 06:41:00 - arrival at 07:20:00 - with duration 00:39
Trip AVE from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 06:41:00 - arrival at 07:20:00 - with duration 00:39
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 07:14:00 - arrival at 08:40:00 - with duration 01:26
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 07:26:00 - arrival at 08:05:00 - with duration 00:39
Trip EUROMED from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 07:26:00 - arrival at 08:05:00 - with duration 00:39
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 07:44:00 - arrival at 09:10:00 - with duration 01:26
Trip REGIONAL from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 08:09:00 - arrival at 09:40:00 - with duration 01:31
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 08:11:00 - arrival at 08:50:00 - with duration 00:39
Trip AVE from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 08:11:00 - arrival at 08:50:00 - with duration 00:39
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 08:19:00 - arrival at 09:40:00 - with duration 01:21
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 08:49:00 - arrival at 10:10:00 - with duration 01:21
Trip EUROMED from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 09:26:00 - arrival at 10:05:00 - with duration 00:39
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 09:26:00 - arrival at 10:05:00 - with duration 00:39
Trip REGIONAL from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 09:39:00 - arrival at 11:10:00 - with duration 01:31
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 10:19:00 - arrival at 11:40:00 - with duration 01:21
Trip REGIONAL from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 11:39:00 - arrival at 13:10:00 - with duration 01:31
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 11:53:00 - arrival at 12:32:00 - with duration 00:39
Trip AVE INT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 11:59:00 - arrival at 12:38:00 - with duration 00:39
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 11:59:00 - arrival at 12:38:00 - with duration 00:39
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 12:19:00 - arrival at 13:40:00 - with duration 01:21
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 13:26:00 - arrival at 14:05:00 - with duration 00:39
Trip REGIONAL from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 13:39:00 - arrival at 15:10:00 - with duration 01:31
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 14:19:00 - arrival at 15:40:00 - with duration 01:21
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 14:49:00 - arrival at 16:10:00 - with duration 01:21
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 15:11:00 - arrival at 15:50:00 - with duration 00:39
Trip AVE from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 15:11:00 - arrival at 15:50:00 - with duration 00:39
Trip REGIONAL from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 15:39:00 - arrival at 17:10:00 - with duration 01:31
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 16:19:00 - arrival at 17:40:00 - with duration 01:21
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 16:19:00 - arrival at 17:40:00 - with duration 01:21
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 16:49:00 - arrival at 18:10:00 - with duration 01:21
Trip REGIONAL from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 17:09:00 - arrival at 18:40:00 - with duration 01:31
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 17:20:00 - arrival at 17:59:00 - with duration 00:39
Trip AVE from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 17:20:00 - arrival at 17:59:00 - with duration 00:39
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 17:26:00 - arrival at 18:05:00 - with duration 00:39
Trip REGIONAL from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 17:39:00 - arrival at 19:10:00 - with duration 01:31
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 17:49:00 - arrival at 19:10:00 - with duration 01:21
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 17:49:00 - arrival at 19:10:00 - with duration 01:21
Trip AVE from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 17:51:00 - arrival at 18:30:00 - with duration 00:39
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 17:51:00 - arrival at 18:30:00 - with duration 00:39
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 18:19:00 - arrival at 19:40:00 - with duration 01:21
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 18:19:00 - arrival at 19:40:00 - with duration 01:21
Trip REGIONAL from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 18:39:00 - arrival at 20:10:00 - with duration 01:31
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 18:49:00 - arrival at 20:10:00 - with duration 01:21
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 18:55:00 - arrival at 19:34:00 - with duration 00:39
Trip AVE INT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 18:55:00 - arrival at 19:34:00 - with duration 00:39
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 19:19:00 - arrival at 20:40:00 - with duration 01:21
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 19:24:00 - arrival at 20:03:00 - with duration 00:39
Trip REGIONAL from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 19:43:00 - arrival at 21:10:00 - with duration 01:27
Trip AVANT from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 19:52:00 - arrival at 20:30:00 - with duration 00:38
Trip REGIONAL from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 20:09:00 - arrival at 21:40:00 - with duration 01:31
Trip REGIONAL from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 20:49:00 - arrival at 22:20:00 - with duration 01:31
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 20:59:00 - arrival at 22:20:00 - with duration 01:21
Trip MD from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 21:19:00 - arrival at 22:40:00 - with duration 01:21
Trip REGIONAL from Estación de tren Girona to Estación de tren Barcelona-Sants - departure at 21:23:00 - arrival at 22:52:00 - with duration 01:29

gerardcl avatar Sep 22 '24 17:09 gerardcl

❯ uvx renfe-cli -f "Chamartin" -t "Vigo Urzaiz" -m 10 -y 2024 -d 4
Loading GTFS data from Renfe web
Provided input 'Chamartin' does a match with 'Station { name: "Estación de tren Madrid-Chamartin", id: "17000" }'
Provided input 'Vigo Urzaiz' does a match with 'Station { name: "Estación de tren Vigo Urzaiz", id: "08223" }'
Today is: 2024-9-30
Searching timetable for date: 2024-10-4
Origin station: Estación de tren Madrid-Chamartin
Destination station: Estación de tren Vigo Urzaiz

=========================TIMETABLE=========================
  Train        |   Departure  |   Arrival    |   Duration    
-----------------------------------------------------------
   ALVIA       |    08:00     |    12:27     |    04:27     
-----------------------------------------------------------
   ALVIA       |    11:20     |    15:38     |    04:18     
-----------------------------------------------------------
   ALVIA       |    16:00     |    20:12     |    04:12     
-----------------------------------------------------------
   AVE         |    19:18     |    23:36     |    04:18     
===========================================================

renfe-cli 5.0 works like a charm 👏🏼 hopefully see some of you at https://2024.es.pycon.org/ 😄

astrojuanlu avatar Sep 30 '24 08:09 astrojuanlu