From bf5418922fc2bf0a1ff94241bbbae4e674f9ec9a Mon Sep 17 00:00:00 2001 From: Ollo Date: Sat, 16 Sep 2023 14:05:39 +0200 Subject: [PATCH] Debug messages in straba module only used in the first call --- client/bin/src/main.rs | 6 ++++-- client/bin/src/straba.rs | 14 ++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index dae615b..96cf04c 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -304,10 +304,12 @@ fn main() { let mut last_data = Option::None; // Test Webcrawler for public transportataion - let mut strabaRes = straba::fetch_data(); + let mut strabaRes = straba::fetch_data(Some(true)); println!("{:?} {:?}s", strabaRes.outbound_station, strabaRes.outbound_diff); println!("{:?} {:?}s", strabaRes.inbound_station , strabaRes.inbound_diff); + // Render start + send_package(ip.to_string(), &last_data, &strabaRes); loop { let st_now = SystemTime::now(); let seconds = st_now.duration_since(UNIX_EPOCH).unwrap().as_secs(); @@ -326,7 +328,7 @@ fn main() { // request once a minute new data if (strabaRes.request_time + 60) < seconds as i64 { - strabaRes = straba::fetch_data(); + strabaRes = straba::fetch_data(None); println!("Update {:?} {:?}s", strabaRes.outbound_station, strabaRes.outbound_diff); println!("Update {:?} {:?}s", strabaRes.inbound_station , strabaRes.inbound_diff); } diff --git a/client/bin/src/straba.rs b/client/bin/src/straba.rs index 0d6455a..9398baf 100644 --- a/client/bin/src/straba.rs +++ b/client/bin/src/straba.rs @@ -82,7 +82,7 @@ pub struct NextDeparture { pub failure: bool, } -pub fn fetch_data() -> NextDeparture { +pub fn fetch_data(debug_print : Option) -> NextDeparture { let st_now = SystemTime::now(); let seconds = st_now.duration_since(UNIX_EPOCH).unwrap().as_secs(); @@ -98,8 +98,6 @@ pub fn fetch_data() -> NextDeparture { request_time : seconds as i64, }; - println!("Start Straba Crawler"); - if result.is_err() { println!("Could not read station response {:?}", result.err()); returnValue.failure = true; @@ -111,8 +109,8 @@ pub fn fetch_data() -> NextDeparture { returnValue.failure = true; return returnValue; } - let rawText = &text.unwrap(); + let rawText = &text.unwrap(); let body: std::result::Result = serde_json::from_str(&rawText); if body.is_err() { @@ -127,7 +125,9 @@ pub fn fetch_data() -> NextDeparture { // parse JSON result.. search of both directions let json = body.unwrap(); for el in (json.graphQL.response.journeys.elements) { - println!("Line {:}", el.line.lineGroup.label); + if (debug_print.is_some() && debug_print.unwrap() == true) { + println!("Line {:}", el.line.lineGroup.label); + } for stop in el.stops { // use only valid data if stop.realtimeDeparture.isoString.is_some() && @@ -136,7 +136,9 @@ pub fn fetch_data() -> NextDeparture { let next_departure = DateTime::parse_from_rfc3339(&txt_departure).unwrap(); let diff = next_departure.timestamp() - (seconds as i64); - println!("To {:} {:} (in {:} seconds)", stop.destinationLabel, txt_departure, diff ); + if (debug_print.is_some() && debug_print.unwrap() == true) { + println!("To {:} {:} (in {:} seconds)", stop.destinationLabel, txt_departure, diff ); + } if stop.destinationLabel.contains("Rheinau") { if (diff < returnValue.outbound_diff) {