mirror of
https://github.com/Death916/deathclock.git
synced 2026-04-10 03:04:40 -07:00
align nba
This commit is contained in:
parent
261943b196
commit
e8b933c376
2 changed files with 21 additions and 10 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
mod sports;
|
mod sports;
|
||||||
use iced::Center;
|
use iced::Center;
|
||||||
use iced::Element;
|
use iced::Element;
|
||||||
|
use iced::Fill;
|
||||||
use iced::widget::{column, image, pane_grid, row, text};
|
use iced::widget::{column, image, pane_grid, row, text};
|
||||||
use sports::Game;
|
use sports::Game;
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
|
|
@ -50,11 +51,21 @@ impl State {
|
||||||
let content: Element<'_, Message> = match pane_state {
|
let content: Element<'_, Message> = match pane_state {
|
||||||
PaneType::NbaPane => {
|
PaneType::NbaPane => {
|
||||||
let games = &state.scores;
|
let games = &state.scores;
|
||||||
column![
|
column(games.iter().map(|game| {
|
||||||
text("NBA").size(50),
|
column![
|
||||||
text(format!("{} vs {}", games[0].team1, games[0].team2)).size(20),
|
row![
|
||||||
text(format!("{} - {}", games[0].score1, games[0].score2)).size(20),
|
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)
|
||||||
|
.into()
|
||||||
|
}))
|
||||||
.padding(5)
|
.padding(5)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
@ -96,10 +107,7 @@ impl Default for State {
|
||||||
news: Vec::new(),
|
news: Vec::new(),
|
||||||
weather: text,
|
weather: text,
|
||||||
location: "Sacramento".to_string(),
|
location: "Sacramento".to_string(),
|
||||||
scores: {
|
scores: { sports::update_nba() },
|
||||||
sports::update_nba();
|
|
||||||
sports::sports()
|
|
||||||
},
|
|
||||||
panes: {
|
panes: {
|
||||||
let (mut panes, nba) = pane_grid::State::new(PaneType::NbaPane);
|
let (mut panes, nba) = pane_grid::State::new(PaneType::NbaPane);
|
||||||
let (weather, _) = panes
|
let (weather, _) = panes
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ pub fn sports() -> Vec<Game> {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_nba() {
|
pub fn update_nba() -> Vec<Game> {
|
||||||
let nba_games =
|
let nba_games =
|
||||||
ureq::get("https://cdn.nba.com/static/json/liveData/scoreboard/todaysScoreboard_00.json")
|
ureq::get("https://cdn.nba.com/static/json/liveData/scoreboard/todaysScoreboard_00.json")
|
||||||
.header("User-Agent", "deathclock-app/1.0")
|
.header("User-Agent", "deathclock-app/1.0")
|
||||||
|
|
@ -61,6 +61,7 @@ pub fn update_nba() {
|
||||||
|
|
||||||
let json: serde_json::Value = serde_json::from_slice(&nba_games).unwrap();
|
let json: serde_json::Value = serde_json::from_slice(&nba_games).unwrap();
|
||||||
let games = json["scoreboard"]["games"].as_array().unwrap();
|
let games = json["scoreboard"]["games"].as_array().unwrap();
|
||||||
|
let mut updated_games: Vec<Game> = Vec::new();
|
||||||
|
|
||||||
for game in games {
|
for game in games {
|
||||||
let game_id = game["gameId"].as_str().unwrap();
|
let game_id = game["gameId"].as_str().unwrap();
|
||||||
|
|
@ -79,6 +80,7 @@ pub fn update_nba() {
|
||||||
period,
|
period,
|
||||||
);
|
);
|
||||||
game.update(&home_score, &away_score, period);
|
game.update(&home_score, &away_score, period);
|
||||||
|
updated_games.push(game);
|
||||||
println!("Game ID: {}", game_id);
|
println!("Game ID: {}", game_id);
|
||||||
println!("Home Team: {}", home_team);
|
println!("Home Team: {}", home_team);
|
||||||
println!("Away Team: {}", away_team);
|
println!("Away Team: {}", away_team);
|
||||||
|
|
@ -86,4 +88,5 @@ pub fn update_nba() {
|
||||||
println!("Away Score: {}", away_score);
|
println!("Away Score: {}", away_score);
|
||||||
println!("Period: {}", period);
|
println!("Period: {}", period);
|
||||||
}
|
}
|
||||||
|
updated_games
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue