get logos

This commit is contained in:
death916 2026-03-17 03:20:46 -07:00
parent 5926501f1e
commit c2bb7f4bdc
3 changed files with 59 additions and 31 deletions

View file

@ -1,32 +1,32 @@
[
{"abbr": "ARI", "name": "Arizona Diamondbacks", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/109.svg"},
{"abbr": "ATL", "name": "Atlanta Braves", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/144.svg"},
{"abbr": "BAL", "name": "Baltimore Orioles", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/110.svg"},
{"abbr": "BOS", "name": "Boston Red Sox", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/111.svg"},
{"abbr": "CHC", "name": "Chicago Cubs", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/112.svg"},
{"abbr": "CHW", "name": "Chicago White Sox", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/145.svg"},
{"abbr": "CIN", "name": "Cincinnati Reds", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/113.svg"},
{"abbr": "CLE", "name": "Cleveland Indians", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/114.svg"},
{"abbr": "COL", "name": "Colorado Rockies", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/115.svg"},
{"abbr": "DET", "name": "Detroit Tigers", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/116.svg"},
{"abbr": "HOU", "name": "Houston Astros", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/117.svg"},
{"abbr": "KCR", "name": "Kansas City Royals", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/118.svg"},
{"abbr": "LAA", "name": "Los Angeles Angels", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/108.svg"},
{"abbr": "LAD", "name": "Los Angeles Dodgers", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/119.svg"},
{"abbr": "MIA", "name": "Miami Marlins", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/146.svg"},
{"abbr": "MIL", "name": "Milwaukee Brewers", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/158.svg"},
{"abbr": "MIN", "name": "Minnesota Twins", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/142.svg"},
{"abbr": "NYM", "name": "New York Mets", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/121.svg"},
{"abbr": "NYY", "name": "New York Yankees", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/147.svg"},
{"abbr": "OAK", "name": "Oakland Athletics", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/133.svg"},
{"abbr": "PHI", "name": "Philadelphia Phillies", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/143.svg"},
{"abbr": "PIT", "name": "Pittsburgh Pirates", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/134.svg"},
{"abbr": "SDP", "name": "San Diego Padres", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/135.svg"},
{"abbr": "SFG", "name": "San Francisco Giants", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/137.svg"},
{"abbr": "SEA", "name": "Seattle Mariners", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/136.svg"},
{"abbr": "STL", "name": "St. Louis Cardinals", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/138.svg"},
{"abbr": "TBR", "name": "Tampa Bay Rays", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/139.svg"},
{"abbr": "TEX", "name": "Texas Rangers", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/140.svg"},
{"abbr": "TOR", "name": "Toronto Blue Jays", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/141.svg"},
{"abbr": "WSN", "name": "Washington Nationals", "logo": "https://www.mlbstatic.com/team-logos/team-cap-on-light/120.svg"}
{"abbr": "ARI", "name": "Arizona Diamondbacks", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/ari.png"},
{"abbr": "ATL", "name": "Atlanta Braves", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/atl.png"},
{"abbr": "BAL", "name": "Baltimore Orioles", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/bal.png"},
{"abbr": "BOS", "name": "Boston Red Sox", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/bos.png"},
{"abbr": "CHC", "name": "Chicago Cubs", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/chc.png"},
{"abbr": "CHW", "name": "Chicago White Sox", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/chw.png"},
{"abbr": "CIN", "name": "Cincinnati Reds", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/cin.png"},
{"abbr": "CLE", "name": "Cleveland Indians", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/cle.png"},
{"abbr": "COL", "name": "Colorado Rockies", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/col.png"},
{"abbr": "DET", "name": "Detroit Tigers", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/det.png"},
{"abbr": "HOU", "name": "Houston Astros", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/hou.png"},
{"abbr": "KCR", "name": "Kansas City Royals", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/kc.png"},
{"abbr": "LAA", "name": "Los Angeles Angels", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/laa.png"},
{"abbr": "LAD", "name": "Los Angeles Dodgers", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/lad.png"},
{"abbr": "MIA", "name": "Miami Marlins", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/mia.png"},
{"abbr": "MIL", "name": "Milwaukee Brewers", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/mil.png"},
{"abbr": "MIN", "name": "Minnesota Twins", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/min.png"},
{"abbr": "NYM", "name": "New York Mets", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/nym.png"},
{"abbr": "NYY", "name": "New York Yankees", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/nyy.png"},
{"abbr": "OAK", "name": "Oakland Athletics", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/oak.png"},
{"abbr": "PHI", "name": "Philadelphia Phillies", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/phi.png"},
{"abbr": "PIT", "name": "Pittsburgh Pirates", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/pit.png"},
{"abbr": "SDP", "name": "San Diego Padres", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/sd.png"},
{"abbr": "SFG", "name": "San Francisco Giants", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/sf.png"},
{"abbr": "SEA", "name": "Seattle Mariners", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/sea.png"},
{"abbr": "STL", "name": "St. Louis Cardinals", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/stl.png"},
{"abbr": "TBR", "name": "Tampa Bay Rays", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/tb.png"},
{"abbr": "TEX", "name": "Texas Rangers", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/tex.png"},
{"abbr": "TOR", "name": "Toronto Blue Jays", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/tor.png"},
{"abbr": "WSN", "name": "Washington Nationals", "logo": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/wsh.png"}
]

View file

@ -9,6 +9,7 @@ use iced::Fill;
use iced::widget::pane_grid::Configuration;
use iced::widget::{column, container, image, pane_grid, row, scrollable, text};
use sports::Game;
pub fn main() -> iced::Result {
iced::run(State::update, State::view)
}
@ -103,15 +104,26 @@ impl State {
PaneType::News => text("News").into(),
PaneType::MlbPane => {
let games = &state.mlb_scores;
let logos = sports::get_mlb_logos();
scrollable(column(games.iter().map(|game| {
let Some(team1_logo) = logos.get(&game.team1) else {
return text("Error: Team 1 logo not found").into();
};
let team1_handle = image::Handle::from_bytes(team1_logo.clone());
let Some(team2_logo) = logos.get(&game.team2) else {
return text("Error: Team 2 logo not found").into();
};
let team2_handle = image::Handle::from_bytes(team2_logo.clone());
container(
column![
row![
text(&game.team1).size(20).width(Fill),
image(team1_handle.clone()).width(50).height(50),
text(&game.team2).size(20).width(Fill),
],
row![
text(&game.score1).size(20).width(Fill),
image(team2_handle.clone()).width(50).height(50),
text(&game.score2).size(20).width(Fill),
],
text(format!("Period: {}", game.period)).size(14),

View file

@ -1,3 +1,4 @@
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub enum Sport {
NBA,
@ -137,7 +138,7 @@ pub fn update_nba() -> Vec<Game> {
updated_games
}
pub fn get_mlb_logos() {
pub fn get_mlb_logos() -> HashMap<String, Vec<u8>> {
let json = std::fs::read_to_string("src/files/mlb_logos.json").unwrap();
let parsed_json: serde_json::Value = serde_json::from_str(&json).unwrap();
let teams = parsed_json.as_array().unwrap();
@ -150,4 +151,19 @@ pub fn get_mlb_logos() {
println!("Logo URL: {}", logo_url);
logos_map.insert(team_name.to_string(), logo_url.to_string());
}
let mut logos_svg_map = std::collections::HashMap::new();
for (team_name, logo_url) in logos_map.iter() {
let response = ureq::get(logo_url)
.header("User-Agent", "deathclock-app/0.1")
.call()
.unwrap();
let image_data = response.into_body().read_to_vec().unwrap();
println!("Logo Data Length: {}", image_data.clone().len());
logos_svg_map.insert(team_name.to_string(), image_data);
println!("Team Name: {}", team_name);
}
logos_svg_map
}