From e55e2240ddbcca9d3c0c0945dabb8a2c74cec8ca Mon Sep 17 00:00:00 2001 From: death916 Date: Thu, 12 Mar 2026 05:25:25 -0700 Subject: [PATCH] add mlb pane --- rust/src/main.rs | 55 ++++++++++++++++++++++++++++++++++++++++------ rust/src/sports.rs | 15 +++++++------ 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/rust/src/main.rs b/rust/src/main.rs index 013c06a..195080e 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -33,7 +33,9 @@ struct State { news: Vec, weather: Vec, location: String, - scores: Vec, + nba_scores: Vec, + mlb_scores: Vec, + // nfl_scores: Vec, panes: pane_grid::State, } impl State { @@ -53,7 +55,7 @@ impl State { pane_grid(&state.panes, |_panes, pane_state, _is_maximized| { let content: Element<'_, Message> = match pane_state { PaneType::NbaPane => { - let games = &state.scores; + let games = &state.nba_scores; column(games.iter().map(|game| { container( column![ @@ -94,7 +96,47 @@ impl State { .into() } PaneType::NflPane => text("NFL").into(), - PaneType::MlbPane => text("MLB").into(), + PaneType::MlbPane => { + let games = &state.mlb_scores; + column(games.iter().map(|game| { + container( + column![ + row![ + text(&game.team1).size(20).width(Fill), + text(&game.team2).size(20).width(Fill), + ], + row![ + text(&game.score1).size(20).width(Fill), + text(&game.score2).size(20).width(Fill), + ], + text(format!("Period: {}", game.period)).size(14), + ] + .padding(10), + ) + .padding(5) + .width(Fill) + .style(|_| container::Style { + background: Some(iced::Background::Color(iced::Color::from_rgb( + 0.2, 0.2, 0.2, + ))), + border: Border { + width: 1.0, + color: iced::Color::WHITE, + radius: 0.0.into(), + }, + text_color: Some(iced::Color::WHITE), + snap: true, + shadow: iced::Shadow { + color: iced::Color::BLACK, + offset: iced::Vector::new(0.0, 0.0), + blur_radius: 10.0, + }, + }) + .into() + })) + .padding(0) + .into() + } PaneType::Main => text("Main").into(), PaneType::Clock => text("clock").into(), PaneType::Weather => { @@ -123,7 +165,7 @@ impl State { impl Default for State { fn default() -> Self { sports::update_mlb(); - + let text = ureq::get("https://v2.wttr.in/Sacramento.png?u0") .header("User-Agent", "deathclock-app/1.0") .call() @@ -138,7 +180,8 @@ impl Default for State { news: Vec::new(), weather: text, location: "Sacramento".to_string(), - scores: { sports::update_nba() }, + nba_scores: { sports::update_nba() }, + mlb_scores: { sports::update_mlb() }, panes: { let (mut panes, nba) = pane_grid::State::new(PaneType::NbaPane); let (weather, _) = panes @@ -151,7 +194,5 @@ impl Default for State { panes }, } - } - } diff --git a/rust/src/sports.rs b/rust/src/sports.rs index a91b07f..4ce76b2 100644 --- a/rust/src/sports.rs +++ b/rust/src/sports.rs @@ -41,7 +41,7 @@ impl Game { } } -pub fn update_mlb() { +pub fn update_mlb() -> Vec { let date = chrono::Local::now().format("%Y-%m-%d").to_string(); let mlb_url = format!( "https://statsapi.mlb.com/api/v1/schedule?sportId=1&date={}", @@ -62,11 +62,13 @@ pub fn update_mlb() { for game in games { let home_team = game["teams"]["away"]["team"]["name"].as_str().unwrap(); - println!("Home Team: {}", home_team); let away_team = game["teams"]["home"]["team"]["name"].as_str().unwrap(); - println!("Away Team: {}", away_team); - let home_score = game["teams"]["away"]["score"].as_str().unwrap_or_else(|| "0"); - let away_score = game["teams"]["home"]["score"].as_str().unwrap_or_else(|| "0"); + let home_score = game["teams"]["away"]["score"] + .as_str() + .unwrap_or_else(|| "0"); + let away_score = game["teams"]["home"]["score"] + .as_str() + .unwrap_or_else(|| "0"); let period = game["status"]["period"] .as_str() .unwrap_or_default() @@ -89,9 +91,8 @@ pub fn update_mlb() { println!("Away Score: {}", away_score); println!("Period: {}", period); } - - // mlb_games_vec + mlb_games_vec } pub fn update_nba() -> Vec {