Parse destination and difference

This commit is contained in:
Ollo 2023-09-16 00:24:53 +02:00
parent e70e0ef068
commit 60139da2bf
2 changed files with 28 additions and 12 deletions

View File

@ -242,10 +242,14 @@ fn send_package(ipaddress: String,
if strabaRes.failure == false {
let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On);
let outbound = &format!("{}: {}", "Rheinau", strabaRes.rheinau);
let outbound = &format!("{}: {}min", strabaRes.outbound_station, (strabaRes.outbound_diff / 60));
Text::new(outbound, Point::new(0, 15), text_style)
.draw(&mut display)
.unwrap();
let inbound = &format!("{}: {}min", strabaRes.inbound_station, (strabaRes.inbound_diff / 60));
Text::new(inbound, Point::new(0, 30), text_style)
.draw(&mut display)
.unwrap();
}
package[1..PACKAGE_LENGTH].copy_from_slice(&display.image);
@ -288,8 +292,8 @@ fn main() {
// Test Webcrawler for public transportataion
let strabaRes = straba::fetch_data();
println!("Rheinau: {:?}", strabaRes.rheinau);
println!("Schönau: {:?}", strabaRes.schoenau);
println!("{:?} {:?}s", strabaRes.outbound_station, strabaRes.outbound_diff);
println!("{:?} {:?}s", strabaRes.inbound_station , strabaRes.inbound_diff);
loop {
let delay = time::Duration::from_millis(10000);

View File

@ -74,16 +74,20 @@ pub struct IsoStringDateTime {
// Return value
pub struct NextDeparture {
pub rheinau: String,
pub schoenau: String,
pub outbound_station: String,
pub outbound_diff: i64,
pub inbound_station: String,
pub inbound_diff: i64,
pub failure: bool,
}
pub fn fetch_data() -> NextDeparture {
let mut returnValue = NextDeparture {
failure : false,
rheinau : String::from(""),
schoenau : String::from(""),
outbound_station : String::from(""),
outbound_diff : -10000,
inbound_station : String::from(""),
inbound_diff : -10000,
};
let st_now = SystemTime::now();
@ -128,13 +132,21 @@ pub fn fetch_data() -> NextDeparture {
for stop in el.stops {
if stop.realtimeDeparture.isoString.is_some() {
let txt_departure = stop.realtimeDeparture.isoString.unwrap();
let next_departure = DateTime::parse_from_rfc3339(&txt_departure);
let next_departure = DateTime::parse_from_rfc3339(&txt_departure).unwrap();
let diff = next_departure.timestamp() - (seconds as i64);
println!("To {:} {:}", stop.destinationLabel, txt_departure);
if returnValue.rheinau == "" {
if returnValue.outbound_station == "" {
if stop.destinationLabel.contains("Rheinau") {
returnValue.rheinau = txt_departure;
} else if returnValue.schoenau == "" {
returnValue.schoenau = txt_departure;
returnValue.outbound_station = stop.destinationLabel;
returnValue.outbound_diff = diff;
} else if stop.destinationLabel.contains("Hochschule") ||
stop.destinationLabel.contains("Hauptbahnhof") ||
stop.destinationLabel.contains("nau") { // Schönau
if returnValue.inbound_station == "" {
returnValue.inbound_station = stop.destinationLabel;
returnValue.inbound_diff = diff;
}
}
}
} else {