46 lines
1.1 KiB
Rust
46 lines
1.1 KiB
Rust
use crate::dsn::dsn_request;
|
|
use reqwest::blocking::Client;
|
|
use crate::config::VisualizerConfig;
|
|
use std::sync::mpsc;
|
|
use std::time::Duration;
|
|
use crate::dsn::models::Station;
|
|
|
|
mod dsn;
|
|
mod config;
|
|
|
|
fn dsn_thread(config: VisualizerConfig, tx: mpsc::Sender<Vec<Station>>) {
|
|
let client = Client::new();
|
|
let sleep_duration = Duration::from_secs(config.polling_rate);
|
|
|
|
loop {
|
|
match dsn_request(&client, &config.dsn_address) {
|
|
Ok(stations) => {
|
|
if tx.send(stations).is_err() {
|
|
break;
|
|
}
|
|
}
|
|
Err(e) => {
|
|
println!("Unable to fetch DSN status: {}", e)
|
|
}
|
|
}
|
|
|
|
std::thread::sleep(sleep_duration);
|
|
}
|
|
}
|
|
|
|
|
|
fn main() {
|
|
let (tx,rx) = mpsc::channel::<Vec<Station>>();
|
|
let config = VisualizerConfig::new("config.toml").unwrap();
|
|
|
|
std::thread::spawn(move || dsn_thread(config, tx));
|
|
|
|
loop {
|
|
let stations = rx.recv().unwrap();
|
|
for station in stations {
|
|
println!("Station: {:?}\n Dishes: {:?}", station.name, station.dishes)
|
|
}
|
|
}
|
|
|
|
}
|