Update tram status once a minute

This commit is contained in:
Ollo 2023-09-16 13:53:21 +02:00
parent 489df6e33b
commit db352edbea

View File

@ -2,6 +2,7 @@
use bit::BitIndex; use bit::BitIndex;
use chrono_tz::Europe::Berlin; use chrono_tz::Europe::Berlin;
use chrono::{DateTime, NaiveDateTime, Utc, Timelike}; use chrono::{DateTime, NaiveDateTime, Utc, Timelike};
use std::time::{SystemTime, UNIX_EPOCH};
use openweathermap::forecast::Weather; use openweathermap::forecast::Weather;
use substring::Substring; use substring::Substring;
use tinybmp::Bmp; use tinybmp::Bmp;
@ -303,11 +304,13 @@ fn main() {
let mut last_data = Option::None; let mut last_data = Option::None;
// Test Webcrawler for public transportataion // Test Webcrawler for public transportataion
let strabaRes = straba::fetch_data(); let mut strabaRes = straba::fetch_data();
println!("{:?} {:?}s", strabaRes.outbound_station, strabaRes.outbound_diff); println!("{:?} {:?}s", strabaRes.outbound_station, strabaRes.outbound_diff);
println!("{:?} {:?}s", strabaRes.inbound_station , strabaRes.inbound_diff); println!("{:?} {:?}s", strabaRes.inbound_station , strabaRes.inbound_diff);
loop { loop {
let st_now = SystemTime::now();
let seconds = st_now.duration_since(UNIX_EPOCH).unwrap().as_secs();
let delay = time::Duration::from_millis(10000); let delay = time::Duration::from_millis(10000);
thread::sleep(delay); thread::sleep(delay);
let answer = openweathermap::update_forecast(&receiver); let answer = openweathermap::update_forecast(&receiver);
@ -321,6 +324,13 @@ fn main() {
} }
} }
// request once a minute new data
if (strabaRes.request_time + 60) < seconds as i64 {
strabaRes = straba::fetch_data();
println!("Update {:?} {:?}s", strabaRes.outbound_station, strabaRes.outbound_diff);
println!("Update {:?} {:?}s", strabaRes.inbound_station , strabaRes.inbound_diff);
}
// Render new image
send_package(ip.to_string(), &last_data, &strabaRes); send_package(ip.to_string(), &last_data, &strabaRes);
} }
} }