From a57371b2cfa2d0f0f6ff1bb29046c99fc0e82250 Mon Sep 17 00:00:00 2001 From: wserr Date: Sun, 7 May 2023 13:44:58 +0200 Subject: [PATCH] Formatting --- microservices/weather/.gitignore | 1 - microservices/weather/src/fetch.rs | 11 +++++++++-- microservices/weather/src/input.rs | 7 +++---- microservices/weather/src/main.rs | 24 ++++++++++++++++++------ microservices/weather/src/publish.rs | 0 microservices/weather/src/write.rs | 2 +- 6 files changed, 31 insertions(+), 14 deletions(-) delete mode 100644 microservices/weather/src/publish.rs diff --git a/microservices/weather/.gitignore b/microservices/weather/.gitignore index f5b3191..9f674f0 100644 --- a/microservices/weather/.gitignore +++ b/microservices/weather/.gitignore @@ -15,7 +15,6 @@ Cargo.lock # App settings Settings.toml - .env # Log files diff --git a/microservices/weather/src/fetch.rs b/microservices/weather/src/fetch.rs index a74edbd..26fb593 100644 --- a/microservices/weather/src/fetch.rs +++ b/microservices/weather/src/fetch.rs @@ -28,7 +28,11 @@ fn construct_weather_data_url( ) -> String { format!( "{}?lat={}&lon={}&dt={}&appid={}", - base_url, latitude, longitude, current_datetime.timestamp(), api_key + base_url, + latitude, + longitude, + current_datetime.timestamp(), + api_key ) } @@ -57,6 +61,9 @@ mod test { "abc", &Utc.with_ymd_and_hms(2023, 1, 2, 1, 0, 0).unwrap(), ); - assert_eq!("http://test?lat=1.14&lon=1.12&dt=1672621200&appid=abc", result); + assert_eq!( + "http://test?lat=1.14&lon=1.12&dt=1672621200&appid=abc", + result + ); } } diff --git a/microservices/weather/src/input.rs b/microservices/weather/src/input.rs index 8015d37..9c7de13 100644 --- a/microservices/weather/src/input.rs +++ b/microservices/weather/src/input.rs @@ -1,9 +1,8 @@ -use serde::Deserialize; use crate::mode::Mode; +use serde::Deserialize; #[derive(Deserialize, Debug)] -pub struct Input -{ +pub struct Input { #[serde(default)] pub program_mode: Mode, pub weather_api_base_url: String, @@ -11,5 +10,5 @@ pub struct Input pub influx_db_base_url: String, pub influx_db_token: String, pub latitude: String, - pub longitude: String + pub longitude: String, } diff --git a/microservices/weather/src/main.rs b/microservices/weather/src/main.rs index 3e12289..4b3f0fc 100644 --- a/microservices/weather/src/main.rs +++ b/microservices/weather/src/main.rs @@ -4,9 +4,9 @@ mod mode; mod write; use anyhow::Result; +use chrono::Utc; use config::Config; use log::info; -use chrono::Utc; #[tokio::main] async fn main() -> Result<()> { @@ -14,9 +14,8 @@ async fn main() -> Result<()> { let settings: input::Input = fetch_settings()?; - match settings.program_mode - { - mode::Mode::ReadWeatherData => read_weather_data(&settings).await? + match settings.program_mode { + mode::Mode::ReadWeatherData => read_weather_data(&settings).await?, }; Ok(()) @@ -24,14 +23,27 @@ async fn main() -> Result<()> { async fn read_weather_data(settings: &input::Input) -> Result<()> { info!("Start fetching weather data..."); - let result = fetch::fetch_weather_data(&settings.weather_api_base_url, &settings.latitude, &settings.longitude, &settings.weather_api_key, &Utc::now()).await?; + let result = fetch::fetch_weather_data( + &settings.weather_api_base_url, + &settings.latitude, + &settings.longitude, + &settings.weather_api_key, + &Utc::now(), + ) + .await?; info!("Start writing weather data..."); let map = write::WeatherReading { wind_speed: result.wind.speed, time: Utc::now(), }; - write::write_weather_data(map, &settings.influx_db_base_url, "homeassistant", &settings.influx_db_token).await?; + write::write_weather_data( + map, + &settings.influx_db_base_url, + "homeassistant", + &settings.influx_db_token, + ) + .await?; Ok(()) } diff --git a/microservices/weather/src/publish.rs b/microservices/weather/src/publish.rs deleted file mode 100644 index e69de29..0000000 diff --git a/microservices/weather/src/write.rs b/microservices/weather/src/write.rs index 54c1006..4345f45 100644 --- a/microservices/weather/src/write.rs +++ b/microservices/weather/src/write.rs @@ -1,6 +1,6 @@ +use anyhow::Result; use chrono::{DateTime, Utc}; use influxdb::{Client, InfluxDbWriteable}; -use anyhow::Result; #[derive(InfluxDbWriteable)] pub struct WeatherReading {