diff --git a/src/main.rs b/src/main.rs index 44807dc..5a439dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #![cfg_attr(debug_assertions, allow(dead_code, unused_imports))] mod weather; mod redsox; +use colored::Colorize; use tabled::{Table, Tabled}; use serde::{Deserialize, Serialize}; use tabled::settings::{ @@ -12,14 +13,14 @@ use tabled::settings::{ struct TableRow { date: String, time_of_day: String, - temp: u64, + temp: i32, red_sox: String, forecast: String, } #[allow(unreachable_code)] fn main() { - let baseball_diamond = '\u{f15ec}'; + let baseball_diamond = '\u{f0852}'; // Set the weather location here. let location = weather::WeatherOfficeLocation { x: 75, diff --git a/src/redsox.rs b/src/redsox.rs index 7bb201c..8f3c4c1 100644 --- a/src/redsox.rs +++ b/src/redsox.rs @@ -51,7 +51,7 @@ pub fn get_upcoming_games() -> Vec { // @todo - change this to be a dynamic request from the API endpoint instead of a local file. let schedule_json: String = fs::read_to_string("/Users/danchadwick/Projects/rust/weather/assets/sox-schedule.json").expect("Unable to read file").to_owned(); let json: Vec = serde_json::from_str(&schedule_json).expect("Something not good?"); - let upcoming_games: &Vec = &json.into_iter().take(7).collect(); + let upcoming_games: &Vec = &json.into_iter().collect(); upcoming_games.to_owned() } diff --git a/src/weather.rs b/src/weather.rs index 47a6948..a2b442b 100644 --- a/src/weather.rs +++ b/src/weather.rs @@ -17,7 +17,7 @@ struct Properties { #[derive(Serialize, Deserialize, Debug)] pub struct WeatherPeriod { pub name: String, - pub temperature: u64, + pub temperature: i32, pub wind_direction: String, pub wind_speed: String, pub detailed_forecast: String, @@ -54,29 +54,17 @@ pub fn get_full_forecast(location: WeatherOfficeLocation) -> Vec .text().unwrap().to_string(); let json: ForecastWrapper = serde_json::from_str(&forecast).expect("JSON was not well-formatted"); let weather_periods: Vec = json.properties.periods.into_iter().collect(); - let icon_forecasts = enhance_forecasts(&weather_periods); - + let icon_forecasts = enhance_forecasts(weather_periods); icon_forecasts } -pub fn enhance_forecasts(periods: &Vec) -> Vec { - let mut rebuilt_periods: Vec = vec![]; - for period in periods { +pub fn enhance_forecasts(mut periods: Vec) -> Vec { + for period in periods.iter_mut() { let icon = detect_icon(&period.short_forecast).unwrap(); let icon_forecast = format!("{} {}", icon, &period.detailed_forecast); - let rebuilt_period = WeatherPeriod { - name: period.name.to_string(), - temperature: period.temperature, - wind_direction: period.wind_direction.to_string(), - wind_speed: period.wind_speed.to_string(), - detailed_forecast: icon_forecast, - short_forecast: period.short_forecast.to_string(), - start_time: period.start_time.to_string(), - }; - rebuilt_periods.push(rebuilt_period); + period.detailed_forecast = icon_forecast; } - - rebuilt_periods + periods } pub fn detect_icon(short_forecast: &String) -> Option {