add subreddits/icons

This commit is contained in:
2019-03-09 18:40:19 -05:00
parent 9c50ede0af
commit 76e208e589
2 changed files with 45 additions and 2 deletions

View File

@@ -17,7 +17,7 @@ impl MarkdownGenerator<'_> {
fn fmt_team(&self, team: &nhlapi::Team) -> String { fn fmt_team(&self, team: &nhlapi::Team) -> String {
let team = self.api.get_team_by_id(team.id); let team = self.api.get_team_by_id(team.id);
format!("{}", team.abbrev) format!("[](/r/{}){}", team.subreddit, team.abbrev)
} }
fn fmt_vs(&self, home_team: &nhlapi::Team, away_team: &nhlapi::Team) -> String { fn fmt_vs(&self, home_team: &nhlapi::Team, away_team: &nhlapi::Team) -> String {

View File

@@ -50,6 +50,7 @@ impl Serialize for Season {
pub struct LeagueRecord { pub struct LeagueRecord {
pub wins: u32, pub wins: u32,
pub losses: u32, pub losses: u32,
#[serde(default)]
pub ot: u32, pub ot: u32,
} }
@@ -294,6 +295,39 @@ pub mod standings {
} }
pub mod teams { pub mod teams {
const SUBREDDITS: &'static str = "\
anaheimducks
coyotes
bostonbruins
sabres
calgaryflames
canes
hawks
coloradoavalanche
bluejackets
dallasstars
detroitredwings
edmontonoilers
floridapanthers
losangeleskings
wildhockey
habs
predators
devils
newyorkislanders
rangers
ottawasenators
flyers
penguins
sanjosesharks
stlouisblues
tampabaylightning
leafs
canucks
goldenknights
caps
winnipegjets";
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize)] #[derive(Debug, Clone, Deserialize, Serialize)]
@@ -314,6 +348,8 @@ pub mod teams {
pub location: String, pub location: String,
pub division: Division, pub division: Division,
pub conference: Conference, pub conference: Conference,
#[serde(default)]
pub subreddit: String,
} }
#[derive(Debug, Clone, Deserialize, Serialize)] #[derive(Debug, Clone, Deserialize, Serialize)]
@@ -330,10 +366,17 @@ pub mod teams {
pub fn get() -> reqwest::Result<Vec<Team>> { pub fn get() -> reqwest::Result<Vec<Team>> {
let client = reqwest::Client::new(); let client = reqwest::Client::new();
let root: Root = client let mut root: Root = client
.get("https://statsapi.web.nhl.com/api/v1/teams") .get("https://statsapi.web.nhl.com/api/v1/teams")
.send()? .send()?
.json()?; .json()?;
root.teams.sort_unstable_by_key(|t| t.full_name.clone());
for (sub, team) in SUBREDDITS.lines().zip(root.teams.iter_mut()) {
team.subreddit = sub.trim().to_string();
}
Ok(root.teams) Ok(root.teams)
} }
} }