2025-04-02 20:39:30 -04:00
|
|
|
#![cfg_attr(debug_assertions, allow(dead_code, unused_imports))]
|
|
|
|
|
mod weather;
|
|
|
|
|
mod redsox;
|
2025-04-05 18:39:04 -04:00
|
|
|
// use colored::Colorize;
|
2025-04-02 23:47:19 -04:00
|
|
|
use tabled::{Table, Tabled};
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
2025-04-02 20:39:30 -04:00
|
|
|
use tabled::settings::{
|
|
|
|
|
peaker::Priority, Width, Style, Alignment, object::Columns
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Tabled)]
|
|
|
|
|
#[tabled(rename_all = "UPPERCASE")]
|
|
|
|
|
struct TableRow {
|
|
|
|
|
date: String,
|
|
|
|
|
time_of_day: String,
|
2025-04-03 22:14:08 -04:00
|
|
|
temp: i32,
|
2025-04-02 20:39:30 -04:00
|
|
|
red_sox: String,
|
|
|
|
|
forecast: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(unreachable_code)]
|
|
|
|
|
fn main() {
|
|
|
|
|
// Set the weather location here.
|
|
|
|
|
let location = weather::WeatherOfficeLocation {
|
|
|
|
|
x: 75,
|
|
|
|
|
y: 59,
|
|
|
|
|
code: "GYX".to_string(),
|
|
|
|
|
};
|
|
|
|
|
let entire_forecast: Vec<weather::WeatherPeriod> = weather::get_full_forecast(location);
|
2025-04-05 18:39:04 -04:00
|
|
|
let sox_games: Vec<redsox::GameInfo> = redsox::get_schedule();
|
|
|
|
|
let baseball_diamond = '\u{f0852}';
|
2025-04-02 20:39:30 -04:00
|
|
|
let mut table_rows: Vec<TableRow> = vec![];
|
|
|
|
|
for i in 0..entire_forecast.len() {
|
2025-04-05 18:39:04 -04:00
|
|
|
let forecast_period = &entire_forecast[i];
|
|
|
|
|
let yyyy_mm_dd = &forecast_period.start_time[0..10];
|
2025-04-02 20:39:30 -04:00
|
|
|
let mut sox_status = String::new();
|
|
|
|
|
// Check if there is a sox game and print opp.
|
|
|
|
|
for sox_game in &sox_games {
|
2025-04-05 18:39:04 -04:00
|
|
|
if sox_game.date == yyyy_mm_dd {
|
|
|
|
|
let mut opp_str = String::from(baseball_diamond);
|
2025-04-02 20:39:30 -04:00
|
|
|
opp_str.push_str(" ");
|
|
|
|
|
opp_str.push_str(&sox_game.opponent);
|
|
|
|
|
sox_status = opp_str;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let row = TableRow {
|
2025-04-05 18:39:04 -04:00
|
|
|
date: yyyy_mm_dd.to_string(),
|
|
|
|
|
time_of_day: forecast_period.name.clone(),
|
|
|
|
|
temp: forecast_period.temperature,
|
2025-04-02 20:39:30 -04:00
|
|
|
red_sox: sox_status,
|
2025-04-05 18:39:04 -04:00
|
|
|
forecast: forecast_period.detailed_forecast.to_string(),
|
2025-04-02 20:39:30 -04:00
|
|
|
};
|
|
|
|
|
table_rows.push(row);
|
|
|
|
|
}
|
2025-04-05 18:39:04 -04:00
|
|
|
render_table(&table_rows);
|
|
|
|
|
}
|
2025-04-02 23:47:19 -04:00
|
|
|
|
2025-04-05 18:39:04 -04:00
|
|
|
fn render_table(rows: &Vec<TableRow>) {
|
2025-04-02 23:47:19 -04:00
|
|
|
// here is where we actually render the table.
|
2025-04-05 18:39:04 -04:00
|
|
|
let mut table = Table::new(rows);
|
2025-04-02 20:39:30 -04:00
|
|
|
table.with(Style::modern());
|
|
|
|
|
table.with((
|
2025-04-05 18:39:04 -04:00
|
|
|
Width::wrap(210).priority(Priority::max(true)),
|
|
|
|
|
Width::increase(50).priority(Priority::min(true)),
|
2025-04-02 20:39:30 -04:00
|
|
|
));
|
|
|
|
|
table.modify(Columns::first(), Alignment::right());
|
2025-04-05 18:39:04 -04:00
|
|
|
println!("{}", table);
|
2025-04-02 20:39:30 -04:00
|
|
|
}
|
|
|
|
|
|