Debug messages in straba module only used in the first call
This commit is contained in:
parent
db352edbea
commit
bf5418922f
@ -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);
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ pub struct NextDeparture {
|
||||
pub failure: bool,
|
||||
}
|
||||
|
||||
pub fn fetch_data() -> NextDeparture {
|
||||
pub fn fetch_data(debug_print : Option<bool>) -> 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<Station, serde_json::Error> = 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user