Rheinau is shown

This commit is contained in:
Ollo 2023-09-15 23:11:35 +02:00
parent c264d26398
commit e70e0ef068
2 changed files with 42 additions and 15 deletions

View File

@ -19,6 +19,7 @@ use std::net::UdpSocket;
use std::{env, thread};
use openweathermap::forecast::Forecast;
use straba::NextDeparture;
// This declaration will look for a file named `straba.rs` and will
// insert its contents inside a module named `straba` under this scope
mod straba;
@ -220,7 +221,9 @@ fn render_weather_icon(condition: &Weather, display: &mut UdpDisplay ){
Image::new(&icon_image.unwrap(), Point::new((IMAGE_WIDTH-40) as i32, 0)).draw(display).unwrap();
}
fn send_package(ipaddress: String, data: &Option<Result<Forecast, String>>) {
fn send_package(ipaddress: String,
data: &Option<Result<Forecast, String>>,
strabaRes: &NextDeparture) {
let mut package: [u8; PACKAGE_LENGTH] = [0; PACKAGE_LENGTH];
// Brightness
@ -237,7 +240,13 @@ fn send_package(ipaddress: String, data: &Option<Result<Forecast, String>>) {
// .unwrap();
render_weather(&mut display, data);
if strabaRes.failure == false {
let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On);
let outbound = &format!("{}: {}", "Rheinau", strabaRes.rheinau);
Text::new(outbound, Point::new(0, 15), text_style)
.draw(&mut display)
.unwrap();
}
package[1..PACKAGE_LENGTH].copy_from_slice(&display.image);
// client need to bind to client port (1 before 4242)
@ -278,8 +287,9 @@ fn main() {
let mut last_data = Option::None;
// Test Webcrawler for public transportataion
let name = straba::fetch_data();
println!("Name: {:?}", name);
let strabaRes = straba::fetch_data();
println!("Rheinau: {:?}", strabaRes.rheinau);
println!("Schönau: {:?}", strabaRes.schoenau);
loop {
let delay = time::Duration::from_millis(10000);
@ -295,7 +305,7 @@ fn main() {
}
}
send_package(ip.to_string(), &last_data);
send_package(ip.to_string(), &last_data, &strabaRes);
}
}
// all the other cases

View File

@ -1,5 +1,5 @@
use chrono::{Utc, DateTime};
use std::time::{SystemTime, Duration, UNIX_EPOCH};
use chrono::DateTime;
use std::time::{SystemTime, UNIX_EPOCH};
use chrono_tz::Europe::Berlin;
/* @file straba.rs
@ -74,11 +74,18 @@ pub struct IsoStringDateTime {
// Return value
pub struct NextDeparture {
pub rheinau: i64,
pub schoenau: i64,
pub rheinau: String,
pub schoenau: String,
pub failure: bool,
}
pub fn fetch_data() -> Option<&'static str> {
pub fn fetch_data() -> NextDeparture {
let mut returnValue = NextDeparture {
failure : false,
rheinau : String::from(""),
schoenau : String::from(""),
};
let st_now = SystemTime::now();
let seconds = st_now.duration_since(UNIX_EPOCH).unwrap().as_secs();
let url = &format!("{}?datetime={}", STATION_URL, seconds);
@ -91,13 +98,15 @@ pub fn fetch_data() -> Option<&'static str> {
println!("Start Straba Crawler");
if result.is_err() {
println!("Could not read station response {:?}", result.err());
return Option::None;
println!("Could not read station response {:?}", result.err());
returnValue.failure = true;
return returnValue;
}
let text = result.unwrap().text();
if text.is_err() {
println!("Could not convert response {:?}", text.err());
return Option::None;
returnValue.failure = true;
return returnValue;
}
let rawText = &text.unwrap();
@ -108,7 +117,8 @@ pub fn fetch_data() -> Option<&'static str> {
println!("------------------------- %< ----------------------------");
println!("{}", &rawText);
println!("------------------------- %< ----------------------------");
return Option::None;
returnValue.failure = true;
return returnValue;
}
// parse JSON result.. search of both directions
@ -120,11 +130,18 @@ pub fn fetch_data() -> Option<&'static str> {
let txt_departure = stop.realtimeDeparture.isoString.unwrap();
let next_departure = DateTime::parse_from_rfc3339(&txt_departure);
println!("To {:} {:}", stop.destinationLabel, txt_departure);
if returnValue.rheinau == "" {
if stop.destinationLabel.contains("Rheinau") {
returnValue.rheinau = txt_departure;
} else if returnValue.schoenau == "" {
returnValue.schoenau = txt_departure;
}
}
} else {
println!("Planned {:} {:?}", stop.destinationLabel, stop.plannedDeparture.isoString)
}
}
}
Some("")
returnValue
}