From db352edbea85157bbb68a61f9187200154ba2002 Mon Sep 17 00:00:00 2001 From: Ollo Date: Sat, 16 Sep 2023 13:53:21 +0200 Subject: [PATCH] Update tram status once a minute --- client/bin/src/main.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index 595cf19..dae615b 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -2,6 +2,7 @@ use bit::BitIndex; use chrono_tz::Europe::Berlin; use chrono::{DateTime, NaiveDateTime, Utc, Timelike}; +use std::time::{SystemTime, UNIX_EPOCH}; use openweathermap::forecast::Weather; use substring::Substring; use tinybmp::Bmp; @@ -303,11 +304,13 @@ fn main() { let mut last_data = Option::None; // 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.inbound_station , strabaRes.inbound_diff); loop { + let st_now = SystemTime::now(); + let seconds = st_now.duration_since(UNIX_EPOCH).unwrap().as_secs(); let delay = time::Duration::from_millis(10000); thread::sleep(delay); 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); } }