diff --git a/Cargo.lock b/Cargo.lock index f6c60a4..5cfb2bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -829,6 +829,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-src" +version = "111.24.0+1.1.1s" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3498f259dab01178c6228c6b00dcef0ed2a2d5e20d648c017861227773ea4abd" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.80" @@ -838,6 +847,7 @@ dependencies = [ "autocfg", "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] @@ -1496,10 +1506,11 @@ checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "weather" -version = "0.1.4" +version = "0.1.6" dependencies = [ "cached-path", "chrono", + "openssl", "serde", "serde-xml-rs", ] diff --git a/Cargo.toml b/Cargo.toml index a1472af..798a32a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "weather" -version = "0.1.5" +version = "0.1.6" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/lib.rs b/src/lib.rs index df2c2af..63e3f08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,7 @@ pub struct Forecast { pub feels_like: i16, pub wind_chill: i16, pub weather_code: i32, + pub weather_code_english: Option, pub min_temp: i16, pub max_temp: i16, pub uv_index: Option, @@ -67,6 +68,7 @@ pub fn get_israeli_weather_forecast() -> Result { if let Ok(mut forecasts) = forecasts { transform_forecast_times_to_datetimes(&mut forecasts); + transform_weather_code_to_english(&mut forecasts); return Ok(forecasts); } else { return Err(0); @@ -90,6 +92,39 @@ fn transform_forecast_times_to_datetimes(forecast: &mut LocationForecasts) { }); } +fn transform_weather_code_to_english(forecast: &mut LocationForecasts) { + forecast.location.iter_mut().for_each(|location| { + location.location_data.forecast.iter_mut().for_each(|forecast| { + forecast.weather_code_english = Some(match forecast.weather_code { + 1010 => "Sandstorms", + 1020 => "Thunderstorms", + 1060 => "Snow", + 1070 => "Light snow", + 1080 => "Sleet", + 1140 => "Rainy", + 1160 => "Fog", + 1220 => "Partly cloudy", + 1230 => "Cloudy", + 1250 => "Clear", + 1260 => "Windy", + 1270 => "Muggy", + 1300 => "Frost", + 1310 => "Hot", + 1320 => "Cold", + 1510 => "Stormy", + 1520 => "Heavy snow", + 1530 => "Partly cloudy possible rain", + 1540 => "Cloudy, possible rain", + 1560 => "Cloudy, light rain", + 1570 => "Dust", + 1580 => "Extremely hot", + 1590 => "Extremely cold", + _ => "Unknown" + }).to_owned().map(|s| s.to_string()); + }); + }); +} + #[cfg(test)] mod tests { #[test]