mirror of
https://github.com/Death916/deathclock.git
synced 2026-04-10 03:04:40 -07:00
start sports updates
This commit is contained in:
parent
1001d60b25
commit
464f109bc0
3 changed files with 62 additions and 32 deletions
2
rust/Cargo.lock
generated
2
rust/Cargo.lock
generated
|
|
@ -3496,6 +3496,8 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"iced",
|
"iced",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"ureq",
|
"ureq",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,6 @@ edition = "2024"
|
||||||
chrono = "0.4.44"
|
chrono = "0.4.44"
|
||||||
iced = { version = "0.14.0", features = ["image"] }
|
iced = { version = "0.14.0", features = ["image"] }
|
||||||
reqwest = "0.13.2"
|
reqwest = "0.13.2"
|
||||||
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
|
serde_json = "1.0.149"
|
||||||
ureq = "3.2.0"
|
ureq = "3.2.0"
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,10 @@ impl Default for State {
|
||||||
news: Vec::new(),
|
news: Vec::new(),
|
||||||
weather: text,
|
weather: text,
|
||||||
location: "Sacramento".to_string(),
|
location: "Sacramento".to_string(),
|
||||||
scores: sports().scores,
|
scores: {
|
||||||
|
sports_updates::update_nba();
|
||||||
|
sports()
|
||||||
|
},
|
||||||
panes: {
|
panes: {
|
||||||
let (mut panes, nba) = pane_grid::State::new(Pane::NbaPane);
|
let (mut panes, nba) = pane_grid::State::new(Pane::NbaPane);
|
||||||
let (weather, _) = panes
|
let (weather, _) = panes
|
||||||
|
|
@ -124,16 +127,18 @@ struct Game {
|
||||||
team2: String,
|
team2: String,
|
||||||
score1: String,
|
score1: String,
|
||||||
score2: String,
|
score2: String,
|
||||||
|
period: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Game {
|
impl Game {
|
||||||
fn new(sport: Sport, team1: &str, team2: &str, score1: &str, score2: &str) -> Self {
|
fn new(sport: Sport, team1: &str, team2: &str, score1: &str, score2: &str, period: u8) -> Self {
|
||||||
Game {
|
Game {
|
||||||
sport,
|
sport,
|
||||||
team1: team1.to_string(),
|
team1: team1.to_string(),
|
||||||
team2: team2.to_string(),
|
team2: team2.to_string(),
|
||||||
score1: score1.to_string(),
|
score1: score1.to_string(),
|
||||||
score2: score2.to_string(),
|
score2: score2.to_string(),
|
||||||
|
period,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,36 +148,57 @@ impl Game {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sports() -> State {
|
fn sports() -> Vec<Game> {
|
||||||
println!("Sports!");
|
println!("Sports!");
|
||||||
let mut state = State {
|
|
||||||
current_time: chrono::Utc::now(),
|
|
||||||
next_alarm: Some(chrono::Utc::now() + chrono::Duration::hours(1)),
|
|
||||||
news: vec!["Breaking news!".to_string()],
|
|
||||||
weather: Vec::new(),
|
|
||||||
location: "Sacramento".to_string(),
|
|
||||||
scores: Vec::new(),
|
|
||||||
panes: pane_grid::State::new(Pane::Main).0,
|
|
||||||
};
|
|
||||||
|
|
||||||
state
|
vec![
|
||||||
.scores
|
Game::new(Sport::NBA, "Lakers", "Warriors", "100", "95", 3),
|
||||||
.push(Game::new(Sport::NBA, "Lakers", "Warriors", "100", "95"));
|
Game::new(Sport::NBA, "Celtics", "Nets", "110", "105", 2),
|
||||||
state
|
Game::new(Sport::MLB, "Red Sox", "Yankees", "100", "95", 1),
|
||||||
.scores
|
]
|
||||||
.push(Game::new(Sport::NBA, "Celtics", "Nets", "110", "105"));
|
}
|
||||||
state
|
|
||||||
.scores
|
|
||||||
.push(Game::new(Sport::MLB, "Red Sox", "Yankees", "100", "95"));
|
|
||||||
println!("{:?}", state.current_time);
|
|
||||||
println!("---------------");
|
|
||||||
|
|
||||||
for game in &state.scores {
|
mod sports_updates {
|
||||||
println!("+----------------------+");
|
use super::Game;
|
||||||
println!("| Sport: {:?}", game.sport);
|
use super::Sport;
|
||||||
println!("| {} vs {}", game.team1, game.team2);
|
|
||||||
println!("| {} - {}", game.score1, game.score2);
|
pub fn update_nba() {
|
||||||
println!("+----------------------+");
|
let nba_games = ureq::get(
|
||||||
|
"https://cdn.nba.com/static/json/liveData/scoreboard/todaysScoreboard_00.json",
|
||||||
|
)
|
||||||
|
.header("User-Agent", "deathclock-app/1.0")
|
||||||
|
.call()
|
||||||
|
.unwrap()
|
||||||
|
.into_body()
|
||||||
|
.read_to_vec()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let json: serde_json::Value = serde_json::from_slice(&nba_games).unwrap();
|
||||||
|
let games = json["scoreboard"]["games"].as_array().unwrap();
|
||||||
|
|
||||||
|
for game in games {
|
||||||
|
let game_id = game["gameId"].as_str().unwrap();
|
||||||
|
let home_team = game["homeTeam"]["teamName"].as_str().unwrap();
|
||||||
|
let away_team = game["awayTeam"]["teamName"].as_str().unwrap();
|
||||||
|
let home_score = game["homeTeam"]["score"].as_u64().unwrap().to_string();
|
||||||
|
let away_score = game["awayTeam"]["score"].as_u64().unwrap().to_string();
|
||||||
|
let period = game["period"].as_u64().unwrap() as u8;
|
||||||
|
|
||||||
|
let mut game = Game::new(
|
||||||
|
Sport::NBA,
|
||||||
|
home_team,
|
||||||
|
away_team,
|
||||||
|
&home_score,
|
||||||
|
&away_score,
|
||||||
|
period,
|
||||||
|
);
|
||||||
|
game.update(&home_score, &away_score);
|
||||||
|
println!("Game ID: {}", game_id);
|
||||||
|
println!("Home Team: {}", home_team);
|
||||||
|
println!("Away Team: {}", away_team);
|
||||||
|
println!("Home Score: {}", home_score);
|
||||||
|
println!("Away Score: {}", away_score);
|
||||||
|
println!("Period: {}", period);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
state
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue