From c264d263981d36c1d2e3a81c6ba8f963efb36a34 Mon Sep 17 00:00:00 2001 From: Ollo Date: Fri, 15 Sep 2023 22:01:43 +0200 Subject: [PATCH] Add time to URL --- client/bin/src/straba.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/client/bin/src/straba.rs b/client/bin/src/straba.rs index 4c8c217..035a6d6 100644 --- a/client/bin/src/straba.rs +++ b/client/bin/src/straba.rs @@ -1,5 +1,7 @@ -use chrono::{Utc, DateTime, NaiveDateTime, Timelike}; +use chrono::{Utc, DateTime}; +use std::time::{SystemTime, Duration, UNIX_EPOCH}; use chrono_tz::Europe::Berlin; + /* @file straba.rs * @brief fetch next depature of light rail vehicle */ @@ -77,7 +79,15 @@ pub struct NextDeparture { } pub fn fetch_data() -> Option<&'static str> { - let result = reqwest::blocking::get(STATION_URL); + let st_now = SystemTime::now(); + let seconds = st_now.duration_since(UNIX_EPOCH).unwrap().as_secs(); + let url = &format!("{}?datetime={}", STATION_URL, seconds); + let result = reqwest::blocking::get(url); + /*let cur_time = readTime( DateTime::::default() ); + println!("Next results after {:?}", cur_time); + + return Some("Debug"); +*/ println!("Start Straba Crawler"); if result.is_err() { @@ -101,11 +111,6 @@ pub fn fetch_data() -> Option<&'static str> { return Option::None; } - let cur_time = DateTime::::default(); - - NaiveDateTime::default().and_utc() - - println!("Next results after {:?}", cur_time); // parse JSON result.. search of both directions let json = body.unwrap(); for el in (json.graphQL.response.journeys.elements) { @@ -114,9 +119,7 @@ pub fn fetch_data() -> Option<&'static str> { if stop.realtimeDeparture.isoString.is_some() { let txt_departure = stop.realtimeDeparture.isoString.unwrap(); let next_departure = DateTime::parse_from_rfc3339(&txt_departure); - if (next_departure.unwrap() > cur_time) { - println!("To {:} {:}", stop.destinationLabel, txt_departure); - } + println!("To {:} {:}", stop.destinationLabel, txt_departure); } else { println!("Planned {:} {:?}", stop.destinationLabel, stop.plannedDeparture.isoString) }