diff --git a/src/main.rs b/src/main.rs index 5519d35..5949ec6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,6 +69,19 @@ pub async fn meteo_weather() -> Result { let precipitation_selector = Selector::parse("#messwerte-niederschlag").unwrap(); let row_selector = Selector::parse("tr").unwrap(); let cell_selector = Selector::parse("td").unwrap(); + let h4_selector = Selector::parse("h4").unwrap(); + + let html_holder = fragment + .select(&h4_selector) + .next() + .map(|e| e.inner_html()); + let date_time = html_holder + .as_ref() + .and_then(|html| html.lines().nth(0).and_then(|line| line.get(7..23))) + .map(|s| s.trim()) + .unwrap_or(""); + + println!("{}", date_time); if let Some(table) = fragment.select(&profile_selector).next() { for row in table.select(&row_selector) { @@ -128,13 +141,14 @@ pub async fn meteo_weather() -> Result { let precipitation = (precipitation * 100.0).round() / 100.00; let cur_date = Local::now(); - let cur_date_formatted = format!("{}", cur_date.format("%Y-%m-%d %H:%M")); + let cur_date_formatted = format!("{}", cur_date.format("%d-%m-%Y %H:%M")); let weather = MucWeather { temperature, pressure, humidity, precipitation, - date: cur_date_formatted + date: cur_date_formatted, + meteo_date: date_time.to_string() }; println!("{:?}", weather); Ok(weather) diff --git a/src/weather_data.rs b/src/weather_data.rs index e954c7e..93082ce 100644 --- a/src/weather_data.rs +++ b/src/weather_data.rs @@ -12,6 +12,8 @@ pub struct MucWeather { pub(crate) precipitation: f64, #[serde(rename = "Date")] pub(crate) date: String, + #[serde(rename = "MeteoDate")] + pub(crate) meteo_date: String, } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]