Lots of good changes - iter_mut on WeatherPeriods, changing to i32 for temp, add colored, get full schedule.
This commit is contained in:
parent
2d936f6272
commit
aa1893fbf6
@ -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,
|
||||
|
||||
@ -51,7 +51,7 @@ pub fn get_upcoming_games() -> Vec<Game> {
|
||||
// @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<Game> = serde_json::from_str(&schedule_json).expect("Something not good?");
|
||||
let upcoming_games: &Vec<Game> = &json.into_iter().take(7).collect();
|
||||
let upcoming_games: &Vec<Game> = &json.into_iter().collect();
|
||||
upcoming_games.to_owned()
|
||||
}
|
||||
|
||||
|
||||
@ -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<WeatherPeriod>
|
||||
.text().unwrap().to_string();
|
||||
let json: ForecastWrapper = serde_json::from_str(&forecast).expect("JSON was not well-formatted");
|
||||
let weather_periods: Vec<WeatherPeriod> = 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<WeatherPeriod>) -> Vec<WeatherPeriod> {
|
||||
let mut rebuilt_periods: Vec<WeatherPeriod> = vec![];
|
||||
for period in periods {
|
||||
pub fn enhance_forecasts(mut periods: Vec<WeatherPeriod>) -> Vec<WeatherPeriod> {
|
||||
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<char> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user