refactored fetch_data-function and added station_id as parameter
This commit is contained in:
@@ -34,7 +34,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let mut last_request = Instant::now();
|
||||
let interval = Duration::from_secs(args.interval as u64);
|
||||
let mut departure_data = tokio::task::spawn_blocking(|| straba::fetch_data(Some(true)))
|
||||
let mut departure_data = tokio::task::spawn_blocking(|| straba::fetch_data(2494, Some(true)))
|
||||
.await
|
||||
.unwrap();
|
||||
let mut data_published = false;
|
||||
@@ -44,7 +44,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if now.duration_since(last_request) > interval {
|
||||
data_published = false;
|
||||
last_request = Instant::now();
|
||||
departure_data = tokio::task::spawn_blocking(|| straba::fetch_data(Some(false)))
|
||||
departure_data = tokio::task::spawn_blocking(|| straba::fetch_data(2494, Some(false)))
|
||||
.await
|
||||
.unwrap();
|
||||
if departure_data.failure {
|
||||
|
||||
@@ -3,7 +3,9 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
const STATION_URL: &str = "https://www.rnv-online.de/rest/departure/2494";
|
||||
const LOOKUP_STATION_URL: &str = "https://www.rnv-online.de/rest/stop?name=";
|
||||
|
||||
const STATION_URL: &str = "https://www.rnv-online.de/rest/departure/";
|
||||
|
||||
/* ******************** JSON Description ****************************** */
|
||||
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
|
||||
@@ -79,10 +81,10 @@ pub struct NextDeparture {
|
||||
pub failure: bool,
|
||||
}
|
||||
|
||||
pub fn fetch_data(debug_print: Option<bool>) -> NextDeparture {
|
||||
pub fn fetch_data(station_id: u64, debug_print: Option<bool>) -> NextDeparture {
|
||||
let st_now = SystemTime::now();
|
||||
let seconds = st_now.duration_since(UNIX_EPOCH).unwrap().as_secs();
|
||||
let url = &format!("{}?datetime={}", STATION_URL, seconds);
|
||||
let url = &format!("{}{}?datetime={}", STATION_URL, station_id, seconds);
|
||||
let result = reqwest::blocking::get(url);
|
||||
|
||||
let mut return_value = NextDeparture {
|
||||
|
||||
Reference in New Issue
Block a user