Formatting
This commit is contained in:
1
microservices/weather/.gitignore
vendored
1
microservices/weather/.gitignore
vendored
@@ -15,7 +15,6 @@ Cargo.lock
|
||||
|
||||
# App settings
|
||||
Settings.toml
|
||||
|
||||
.env
|
||||
|
||||
# Log files
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use anyhow::Result;
|
||||
use chrono::{DateTime, Utc};
|
||||
use influxdb::{Client, InfluxDbWriteable};
|
||||
use anyhow::Result;
|
||||
|
||||
#[derive(InfluxDbWriteable)]
|
||||
pub struct WeatherReading {
|
||||
|
||||
Reference in New Issue
Block a user