Skip to content

Commit

Permalink
feat: translate weather code to english
Browse files Browse the repository at this point in the history
  • Loading branch information
barakplasma committed Feb 9, 2023
1 parent b09eafe commit 6e83461
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
13 changes: 12 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 35 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct Forecast {
pub feels_like: i16,
pub wind_chill: i16,
pub weather_code: i32,
pub weather_code_english: Option<String>,
pub min_temp: i16,
pub max_temp: i16,
pub uv_index: Option<i16>,
Expand All @@ -67,6 +68,7 @@ pub fn get_israeli_weather_forecast() -> Result<LocationForecasts, i8> {

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);
Expand All @@ -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]
Expand Down

0 comments on commit 6e83461

Please sign in to comment.