stcp_scraper/schedules/
mod.rs

1use serde::Serialize;
2
3use crate::Error;
4use fetch::fetch_schedules_in_stop;
5use parse::parse_html;
6use crate::lines;
7
8mod fetch;
9mod parse;
10
11#[derive(Debug, PartialEq, Serialize)]
12pub struct Schedule {
13    /// Line code, e.g. 600 or 107 (for ZC line)
14    line: lines::Code,
15
16    time: String,
17
18    destination: String,
19
20    stop: String,
21}
22
23/// Fetches the schedules given a stop.
24/// `stop_code` is the code given by STCP to the stop. You can check it in the `Código` part of the table for line 200 here: https://www.stcp.pt/pt/viajar/linhas/?linha=200
25pub fn fetch_next_buses(stop_code: &str) -> Result<Vec<Schedule>, Error> {
26    let html = fetch_schedules_in_stop(stop_code, None)?;
27
28    parse_html(stop_code, &html)
29}