switch from scraping to API queries
This commit is contained in:
+22
-4
@@ -1,6 +1,6 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::fmt::{Debug, Display};
|
||||
|
||||
use anyhow::Result;
|
||||
use chrono::{DateTime, Local, TimeZone, Utc};
|
||||
@@ -8,7 +8,7 @@ use serde::{de, Deserialize, Deserializer};
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
struct Departure {
|
||||
pub struct Departure {
|
||||
id: String,
|
||||
dl_id: String,
|
||||
line_name: String,
|
||||
@@ -54,12 +54,12 @@ struct CancelReason {
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
struct Response {
|
||||
pub struct Response {
|
||||
name: String,
|
||||
status: Status,
|
||||
place: String,
|
||||
expiration_time: String,
|
||||
departures: Vec<Departure>,
|
||||
pub departures: Vec<Departure>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
@@ -97,3 +97,21 @@ where
|
||||
Err(_) => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Departure {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&format!("{} {}\n", &self.line_name, &self.direction))?;
|
||||
|
||||
let scheduled_time = self.scheduled_time.format("%H:%M");
|
||||
f.write_str(&format!("departure: {}", &scheduled_time))?;
|
||||
|
||||
if let Some(real_time) = self.real_time {
|
||||
let actual_time = real_time.format("%H:%M");
|
||||
if real_time != self.scheduled_time {
|
||||
f.write_str(&format!(" | delayed: {actual_time} "))?;
|
||||
}
|
||||
}
|
||||
f.write_str("\n")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user