1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use serde::Serialize;

use crate::Error;
use fetch::fetch_schedules_in_stop;
use parse::parse_html;
use crate::lines;

mod fetch;
mod parse;

#[derive(Debug, PartialEq, Serialize)]
pub struct Schedule {
    /// Line code, e.g. 600 or 107 (for ZC line)
    line: lines::Code,

    time: String,

    destination: String,

    stop: String,
}

/// Fetches the schedules given a stop.
/// `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
pub fn fetch_next_buses(stop_code: &str) -> Result<Vec<Schedule>, Error> {
    let html = fetch_schedules_in_stop(stop_code, None)?;

    parse_html(stop_code, &html)
}