Formatting

This commit is contained in:
2023-05-07 13:44:58 +02:00
parent 76a242f58b
commit a57371b2cf
6 changed files with 31 additions and 14 deletions

View File

@@ -15,7 +15,6 @@ Cargo.lock
# App settings # App settings
Settings.toml Settings.toml
.env .env
# Log files # Log files

View File

@@ -28,7 +28,11 @@ fn construct_weather_data_url(
) -> String { ) -> String {
format!( format!(
"{}?lat={}&lon={}&dt={}&appid={}", "{}?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", "abc",
&Utc.with_ymd_and_hms(2023, 1, 2, 1, 0, 0).unwrap(), &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
);
} }
} }

View File

@@ -1,9 +1,8 @@
use serde::Deserialize;
use crate::mode::Mode; use crate::mode::Mode;
use serde::Deserialize;
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
pub struct Input pub struct Input {
{
#[serde(default)] #[serde(default)]
pub program_mode: Mode, pub program_mode: Mode,
pub weather_api_base_url: String, pub weather_api_base_url: String,
@@ -11,5 +10,5 @@ pub struct Input
pub influx_db_base_url: String, pub influx_db_base_url: String,
pub influx_db_token: String, pub influx_db_token: String,
pub latitude: String, pub latitude: String,
pub longitude: String pub longitude: String,
} }

View File

@@ -4,9 +4,9 @@ mod mode;
mod write; mod write;
use anyhow::Result; use anyhow::Result;
use chrono::Utc;
use config::Config; use config::Config;
use log::info; use log::info;
use chrono::Utc;
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
@@ -14,9 +14,8 @@ async fn main() -> Result<()> {
let settings: input::Input = fetch_settings()?; let settings: input::Input = fetch_settings()?;
match settings.program_mode match settings.program_mode {
{ mode::Mode::ReadWeatherData => read_weather_data(&settings).await?,
mode::Mode::ReadWeatherData => read_weather_data(&settings).await?
}; };
Ok(()) Ok(())
@@ -24,14 +23,27 @@ async fn main() -> Result<()> {
async fn read_weather_data(settings: &input::Input) -> Result<()> { async fn read_weather_data(settings: &input::Input) -> Result<()> {
info!("Start fetching weather data..."); 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..."); info!("Start writing weather data...");
let map = write::WeatherReading { let map = write::WeatherReading {
wind_speed: result.wind.speed, wind_speed: result.wind.speed,
time: Utc::now(), 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(()) Ok(())
} }

View File

@@ -1,6 +1,6 @@
use anyhow::Result;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use influxdb::{Client, InfluxDbWriteable}; use influxdb::{Client, InfluxDbWriteable};
use anyhow::Result;
#[derive(InfluxDbWriteable)] #[derive(InfluxDbWriteable)]
pub struct WeatherReading { pub struct WeatherReading {