First set of commits for realtime support
This commit is contained in:
parent
cba2b17f57
commit
40f8c46d80
|
|
@ -2,6 +2,7 @@ mod arrival;
|
|||
mod loader;
|
||||
mod utils;
|
||||
mod refresher;
|
||||
mod realtime;
|
||||
pub mod structs;
|
||||
use chrono::{DateTime, Local, Timelike};
|
||||
use log::{debug, trace};
|
||||
|
|
@ -10,7 +11,7 @@ use gtfs_structures::{Exception, RawTrip};
|
|||
use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Gtfs, Preferences, Error}};
|
||||
|
||||
|
||||
impl Gtfs {
|
||||
impl Gtfs<'_> {
|
||||
|
||||
pub fn get_next_arrivals_for(&self, target_datetime: &DateTime<Local>) -> Option<Vec<Arrival<'_>>> {
|
||||
let naive_target = target_datetime.naive_local();
|
||||
|
|
@ -98,6 +99,7 @@ impl Gtfs {
|
|||
let mut zip_reader = zip::ZipArchive::new(zip_file)?;
|
||||
|
||||
let mut gtfs: Gtfs = Gtfs {
|
||||
preferences: prefs,
|
||||
agencies: Vec::new(),
|
||||
calendar: HashMap::new(),
|
||||
calendar_dates: HashMap::new(),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
/***
|
||||
* Implementation of GTFS-R polling
|
||||
*/
|
||||
|
||||
use std::{str::FromStr, time::Duration};
|
||||
|
||||
use reqwest::{blocking::Client, header::{HeaderName, HeaderValue}};
|
||||
|
||||
use crate::gtfs::structs::{Arrival, Error, Gtfs};
|
||||
|
||||
impl Gtfs<'_> {
|
||||
fn realtime_update (&self, arrivals: Vec<Arrival<'_>>) -> Result<bool, Error>{
|
||||
|
||||
// Poll GTFS-R API
|
||||
let client = Client::builder()
|
||||
.timeout(Duration::from_secs(10))
|
||||
.connect_timeout(Duration::from_secs(5))
|
||||
.build()?;
|
||||
|
||||
let mut response = client
|
||||
.get(self.preferences.realtime_url)
|
||||
.header("x-api-key", self.preferences.realtime_api_key)
|
||||
.send()?;
|
||||
|
||||
// Parse response
|
||||
let response = json::rdr
|
||||
|
||||
// Match deltas to existing arrivals
|
||||
|
||||
// Update the arrival times
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -74,7 +74,10 @@ impl Preferences {
|
|||
|
||||
// The main GTFS struct. This is similar to (but not exactly) gtfs-structures::Gtfs because we don't need everything
|
||||
#[derive(Debug)]
|
||||
pub struct Gtfs {
|
||||
pub struct Gtfs<'a> {
|
||||
/// A copy of the preferences struct
|
||||
pub(crate) preferences: &'a Preferences,
|
||||
|
||||
/// All agencies. They can not be read by `agency_id`, as it is not a required field
|
||||
pub(crate) agencies: Vec<Agency>,
|
||||
/// All Calendar by `service_id`
|
||||
|
|
|
|||
Loading…
Reference in New Issue