Correct stdout, updating lib and some clippy clean
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
fd4affdb17
commit
1affcb9d1a
114
Cargo.lock
generated
114
Cargo.lock
generated
@ -30,9 +30,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64"
|
name = "base64"
|
||||||
version = "0.13.1"
|
version = "0.21.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "billboard"
|
name = "billboard"
|
||||||
@ -193,9 +193,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.6"
|
version = "1.0.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
|
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
@ -214,9 +214,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.146"
|
version = "0.2.147"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b"
|
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
@ -289,18 +289,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.60"
|
version = "1.0.66"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406"
|
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.28"
|
version = "1.0.32"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488"
|
checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
@ -342,21 +342,41 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustls"
|
name = "rustls"
|
||||||
version = "0.20.8"
|
version = "0.21.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f"
|
checksum = "79ea77c539259495ce8ca47f53e66ae0330a8819f67e23ac96ca02f50e7b7d36"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"ring",
|
"ring",
|
||||||
|
"rustls-webpki 0.101.2",
|
||||||
"sct",
|
"sct",
|
||||||
"webpki",
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustls-webpki"
|
||||||
|
version = "0.100.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b"
|
||||||
|
dependencies = [
|
||||||
|
"ring",
|
||||||
|
"untrusted",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustls-webpki"
|
||||||
|
version = "0.101.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "513722fd73ad80a71f72b61009ea1b584bcfa1483ca93949c8f290298837fa59"
|
||||||
|
dependencies = [
|
||||||
|
"ring",
|
||||||
|
"untrusted",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.13"
|
version = "1.0.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
|
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sct"
|
name = "sct"
|
||||||
@ -370,29 +390,29 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.164"
|
version = "1.0.178"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d"
|
checksum = "60363bdd39a7be0266a520dab25fdc9241d2f987b08a01e01f0ec6d06a981348"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.164"
|
version = "1.0.178"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68"
|
checksum = "f28482318d6641454cb273da158647922d1be6b5a2fcc6165cd89ebdd7ed576b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.18",
|
"syn 2.0.27",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.97"
|
version = "1.0.104"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bdf3bf93142acad5821c99197022e170842cdbc1c30482b98750c688c640842a"
|
checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
@ -448,9 +468,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.18"
|
version = "2.0.27"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e"
|
checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -478,22 +498,22 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.40"
|
version = "1.0.44"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
|
checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror-impl",
|
"thiserror-impl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror-impl"
|
name = "thiserror-impl"
|
||||||
version = "1.0.40"
|
version = "1.0.44"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.18",
|
"syn 2.0.27",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -519,9 +539,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.9"
|
version = "1.0.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0"
|
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-normalization"
|
name = "unicode-normalization"
|
||||||
@ -552,19 +572,19 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ureq"
|
name = "ureq"
|
||||||
version = "2.6.2"
|
version = "2.7.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "338b31dd1314f68f3aabf3ed57ab922df95ffcd902476ca7ba3c4ce7b908c46d"
|
checksum = "0b11c96ac7ee530603dcdf68ed1557050f374ce55a5a07193ebf8cbc9f8927e9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"flate2",
|
"flate2",
|
||||||
"log",
|
"log",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustls",
|
"rustls",
|
||||||
|
"rustls-webpki 0.100.1",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"url",
|
"url",
|
||||||
"webpki",
|
|
||||||
"webpki-roots",
|
"webpki-roots",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -618,7 +638,7 @@ dependencies = [
|
|||||||
"once_cell",
|
"once_cell",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.18",
|
"syn 2.0.27",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -640,7 +660,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.18",
|
"syn 2.0.27",
|
||||||
"wasm-bindgen-backend",
|
"wasm-bindgen-backend",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
@ -661,23 +681,13 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "webpki"
|
|
||||||
version = "0.22.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd"
|
|
||||||
dependencies = [
|
|
||||||
"ring",
|
|
||||||
"untrusted",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webpki-roots"
|
name = "webpki-roots"
|
||||||
version = "0.22.6"
|
version = "0.23.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87"
|
checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"webpki",
|
"rustls-webpki 0.100.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -717,7 +727,7 @@ version = "0.48.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-targets 0.48.0",
|
"windows-targets 0.48.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -737,9 +747,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-targets"
|
name = "windows-targets"
|
||||||
version = "0.48.0"
|
version = "0.48.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
|
checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows_aarch64_gnullvm 0.48.0",
|
"windows_aarch64_gnullvm 0.48.0",
|
||||||
"windows_aarch64_msvc 0.48.0",
|
"windows_aarch64_msvc 0.48.0",
|
||||||
|
@ -12,11 +12,11 @@ impl Coordinates {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_correct_latitude(&self) -> bool {
|
pub fn is_correct_latitude(&self) -> bool {
|
||||||
return self.latitude > -90.0 && self.latitude < 90.0;
|
self.latitude > -90.0 && self.latitude < 90.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_correct_longitude(&self) -> bool {
|
pub fn is_correct_longitude(&self) -> bool {
|
||||||
return self.longitude > -180.0 && self.longitude < 180.0;
|
self.longitude > -180.0 && self.longitude < 180.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,6 @@ impl CurrentWeatherExtractor {
|
|||||||
if self.params.winddirection || self.params.all {
|
if self.params.winddirection || self.params.all {
|
||||||
output.data.winddirection = Some(self.current_weather.winddirection);
|
output.data.winddirection = Some(self.current_weather.winddirection);
|
||||||
}
|
}
|
||||||
|
output
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -16,58 +18,45 @@ pub struct CurrentWeatherOutput {
|
|||||||
pub data: CurrentWeatherOutputModel,
|
pub data: CurrentWeatherOutputModel,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CurrentWeatherOutput {
|
impl Display for CurrentWeatherOutput {
|
||||||
pub fn new(
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
format: DataFormat,
|
|
||||||
temperature_unit: TempUnit,
|
|
||||||
speed_unit: SpeedUnit,
|
|
||||||
) -> CurrentWeatherOutput {
|
|
||||||
CurrentWeatherOutput {
|
|
||||||
format,
|
|
||||||
temperature_unit,
|
|
||||||
speed_unit,
|
|
||||||
data: CurrentWeatherOutputModel::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_string(&self) -> String {
|
|
||||||
if DataFormat::JSON == self.format {
|
if DataFormat::JSON == self.format {
|
||||||
serde_json::to_string(&self.data).unwrap()
|
write!(f, "{}", serde_json::to_string(&self.data).unwrap())
|
||||||
} else {
|
} else {
|
||||||
let mut string_vec: Vec<String> = Vec::new();
|
let mut string_vec: Vec<String> = Vec::new();
|
||||||
|
|
||||||
if DataFormat::Normal == self.format {
|
if DataFormat::Normal == self.format {
|
||||||
string_vec.push(self.create_header());
|
string_vec.push(self.create_header());
|
||||||
} else {
|
} else {
|
||||||
if self.data.latitude.is_some() {
|
if let Some(latitude) = self.data.latitude {
|
||||||
string_vec.push(self.data.latitude.unwrap().to_string())
|
string_vec.push(latitude.to_string())
|
||||||
}
|
}
|
||||||
if self.data.longitude.is_some() {
|
if let Some(longitude) = self.data.longitude {
|
||||||
string_vec.push(self.data.longitude.unwrap().to_string())
|
string_vec.push(longitude.to_string())
|
||||||
}
|
}
|
||||||
if self.data.city.is_some() {
|
if let Some(city) = &self.data.city {
|
||||||
string_vec.push(self.data.city.clone().unwrap().to_string())
|
string_vec.push(city.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_day = self.extract_day();
|
let is_day = self.extract_day();
|
||||||
if is_day.is_some() {
|
if let Some(is_day) = is_day {
|
||||||
string_vec.push(is_day.unwrap());
|
string_vec.push(is_day);
|
||||||
}
|
}
|
||||||
|
|
||||||
let temperature = self.extract_temperature();
|
let temperature = self.extract_temperature();
|
||||||
if temperature.is_some() {
|
if let Some(temperature) = temperature {
|
||||||
string_vec.push(temperature.unwrap());
|
string_vec.push(temperature);
|
||||||
}
|
}
|
||||||
|
|
||||||
let windspeed = self.extract_wind_speed();
|
let windspeed = self.extract_wind_speed();
|
||||||
if windspeed.is_some() {
|
if let Some(windspeed) = windspeed {
|
||||||
string_vec.push(windspeed.unwrap());
|
string_vec.push(windspeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
let winddirection = self.extract_wind_direction();
|
let winddirection = self.extract_wind_direction();
|
||||||
if winddirection.is_some() {
|
if let Some(winddirection) = winddirection {
|
||||||
string_vec.push(winddirection.unwrap());
|
string_vec.push(winddirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
if DataFormat::Normal == self.format
|
if DataFormat::Normal == self.format
|
||||||
@ -90,14 +79,26 @@ impl CurrentWeatherOutput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if DataFormat::Clean == self.format {
|
if DataFormat::Clean == self.format {
|
||||||
let final_string = string_vec.join(",");
|
write!(f, "{}", string_vec.join(","))
|
||||||
final_string
|
|
||||||
} else {
|
} else {
|
||||||
string_vec.push(self.create_footer());
|
string_vec.push(self.create_footer());
|
||||||
string_vec.join("\n")
|
write!(f, "{}", string_vec.join("\n"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CurrentWeatherOutput {
|
||||||
|
pub fn new(
|
||||||
|
format: DataFormat,
|
||||||
|
temperature_unit: TempUnit,
|
||||||
|
speed_unit: SpeedUnit,
|
||||||
|
) -> CurrentWeatherOutput {
|
||||||
|
CurrentWeatherOutput {
|
||||||
|
format, temperature_unit, speed_unit,
|
||||||
|
data: CurrentWeatherOutputModel::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn create_header(&self) -> String {
|
fn create_header(&self) -> String {
|
||||||
let mut title_header: Vec<String> = Vec::new();
|
let mut title_header: Vec<String> = Vec::new();
|
||||||
@ -166,15 +167,15 @@ impl CurrentWeatherOutput {
|
|||||||
|
|
||||||
fn parse_custom_data(&self, data: &str, custom: &str) -> String {
|
fn parse_custom_data(&self, data: &str, custom: &str) -> String {
|
||||||
if self.format == DataFormat::Clean {
|
if self.format == DataFormat::Clean {
|
||||||
format!("{data}")
|
data.to_string()
|
||||||
} else {
|
} else {
|
||||||
format!("{custom}")
|
custom.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_simple_data(&self, data: &str, descriptor: &str, end_text: Option<&str>) -> String {
|
fn parse_simple_data(&self, data: &str, descriptor: &str, end_text: Option<&str>) -> String {
|
||||||
if self.format == DataFormat::Clean {
|
if self.format == DataFormat::Clean {
|
||||||
format!("{data}")
|
data.to_string()
|
||||||
} else {
|
} else {
|
||||||
let end_text = end_text.unwrap_or("");
|
let end_text = end_text.unwrap_or("");
|
||||||
format!("{descriptor}: {data}{end_text}")
|
format!("{descriptor}: {data}{end_text}")
|
||||||
|
@ -14,31 +14,3 @@ pub struct CurrentWeatherPrintParams {
|
|||||||
pub include_city: bool,
|
pub include_city: bool,
|
||||||
pub format: DataFormat,
|
pub format: DataFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CurrentWeatherPrintParams {
|
|
||||||
pub fn new(
|
|
||||||
all: bool,
|
|
||||||
is_day: bool,
|
|
||||||
temperature: bool,
|
|
||||||
temperature_unit: TempUnit,
|
|
||||||
windspeed: bool,
|
|
||||||
speed_unit: SpeedUnit,
|
|
||||||
winddirection: bool,
|
|
||||||
include_coords: bool,
|
|
||||||
include_city: bool,
|
|
||||||
format: DataFormat,
|
|
||||||
) -> CurrentWeatherPrintParams {
|
|
||||||
CurrentWeatherPrintParams {
|
|
||||||
all,
|
|
||||||
is_day,
|
|
||||||
temperature,
|
|
||||||
temperature_unit,
|
|
||||||
windspeed,
|
|
||||||
speed_unit,
|
|
||||||
winddirection,
|
|
||||||
include_coords,
|
|
||||||
include_city,
|
|
||||||
format,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::{create_dir_all, File},
|
fs::{create_dir_all, File},
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
path::PathBuf,
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::ip_api::ip_location::IpLocation;
|
use crate::ip_api::ip_location::IpLocation;
|
||||||
@ -60,15 +60,13 @@ pub fn get_from_cache(ip: &str) -> Option<IpLocation> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_in_cache(path: &PathBuf) -> bool {
|
fn is_in_cache(path: &Path) -> bool {
|
||||||
path.is_file()
|
path.is_file()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cache_dir() -> Option<PathBuf> {
|
fn get_cache_dir() -> Option<PathBuf> {
|
||||||
let dir = ProjectDirs::from("com", "midefos", "open-meteo-cli");
|
let dir = ProjectDirs::from("com", "midefos", "open-meteo-cli");
|
||||||
if dir.is_some() {
|
if let Some(project_dir) = &dir {
|
||||||
let project_dir = dir.unwrap();
|
|
||||||
|
|
||||||
let cache_dir = project_dir.cache_dir();
|
let cache_dir = project_dir.cache_dir();
|
||||||
if !cache_dir.exists() {
|
if !cache_dir.exists() {
|
||||||
let res = create_dir_all(cache_dir);
|
let res = create_dir_all(cache_dir);
|
||||||
@ -76,7 +74,6 @@ fn get_cache_dir() -> Option<PathBuf> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(cache_dir.to_owned())
|
Some(cache_dir.to_owned())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
24
src/main.rs
24
src/main.rs
@ -6,7 +6,7 @@ mod current_weather_output_model;
|
|||||||
mod current_weather_print_params;
|
mod current_weather_print_params;
|
||||||
|
|
||||||
mod ifconfig {
|
mod ifconfig {
|
||||||
pub mod ifconfig;
|
pub mod ifconfig_api;
|
||||||
}
|
}
|
||||||
|
|
||||||
mod formats {
|
mod formats {
|
||||||
@ -16,14 +16,14 @@ mod formats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod ip_api {
|
mod ip_api {
|
||||||
pub mod ip_api;
|
pub mod ip_api_api;
|
||||||
pub mod ip_location;
|
pub mod ip_location;
|
||||||
pub mod ip_location_cache;
|
pub mod ip_location_cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
mod open_meteo {
|
mod open_meteo {
|
||||||
pub mod current_weather;
|
pub mod current_weather;
|
||||||
pub mod open_meteo;
|
pub mod open_meteo_api;
|
||||||
}
|
}
|
||||||
|
|
||||||
use billboard::{Alignment, Billboard};
|
use billboard::{Alignment, Billboard};
|
||||||
@ -36,9 +36,9 @@ use cli::Arguments;
|
|||||||
use coords::Coordinates;
|
use coords::Coordinates;
|
||||||
use current_weather_extractor::CurrentWeatherExtractor;
|
use current_weather_extractor::CurrentWeatherExtractor;
|
||||||
use current_weather_print_params::CurrentWeatherPrintParams;
|
use current_weather_print_params::CurrentWeatherPrintParams;
|
||||||
use ifconfig::ifconfig::extract_public_ip;
|
use ifconfig::ifconfig_api::extract_public_ip;
|
||||||
use ip_api::ip_api::extract_coords_and_city;
|
use ip_api::ip_api_api::extract_coords_and_city;
|
||||||
use open_meteo::open_meteo::request_current_weather;
|
use open_meteo::open_meteo_api::request_current_weather;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let opts = Arguments::from_args();
|
let opts = Arguments::from_args();
|
||||||
@ -98,8 +98,8 @@ fn main() {
|
|||||||
let ip_location;
|
let ip_location;
|
||||||
let cache_ip_location = get_from_cache(&ip);
|
let cache_ip_location = get_from_cache(&ip);
|
||||||
|
|
||||||
if cache_ip_location.is_some() {
|
if let Some(cache_ip_location) = cache_ip_location {
|
||||||
ip_location = cache_ip_location.unwrap();
|
ip_location = cache_ip_location;
|
||||||
} else {
|
} else {
|
||||||
let ip_location_res = extract_coords_and_city(&ip);
|
let ip_location_res = extract_coords_and_city(&ip);
|
||||||
ip_location = ip_location_res.unwrap_or_else(|_| {
|
ip_location = ip_location_res.unwrap_or_else(|_| {
|
||||||
@ -130,7 +130,7 @@ fn main() {
|
|||||||
format = DataFormat::JSON;
|
format = DataFormat::JSON;
|
||||||
}
|
}
|
||||||
|
|
||||||
let print_params = CurrentWeatherPrintParams::new(
|
let print_params = CurrentWeatherPrintParams {
|
||||||
all,
|
all,
|
||||||
is_day,
|
is_day,
|
||||||
temperature,
|
temperature,
|
||||||
@ -141,7 +141,7 @@ fn main() {
|
|||||||
include_coords,
|
include_coords,
|
||||||
include_city,
|
include_city,
|
||||||
format,
|
format,
|
||||||
);
|
};
|
||||||
|
|
||||||
let current_weather_printer =
|
let current_weather_printer =
|
||||||
CurrentWeatherExtractor::new(current_weather, print_params, coordinates, city);
|
CurrentWeatherExtractor::new(current_weather, print_params, coordinates, city);
|
||||||
@ -151,9 +151,9 @@ fn main() {
|
|||||||
.text_alignment(Alignment::Left)
|
.text_alignment(Alignment::Left)
|
||||||
.box_alignment(Alignment::Left)
|
.box_alignment(Alignment::Left)
|
||||||
.build()
|
.build()
|
||||||
.eprint(output.to_string());
|
.print(output.to_string());
|
||||||
} else {
|
} else {
|
||||||
println!("{}", output.to_string());
|
println!("{}", output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user