How to Watch a Hockey Game - Game Play

Game Structure

Hockey has some stuff in common with live theater. No ... really! 😁

They both have dressing rooms and they both have intermission ... but that is probably where the similarities end.

Each hockey game is split into three 20 minute periods. There is an intermission between each period that lasts 18 minutes. During the intermission the players go back to the dressing room to regroup and chat about the previous period a strategize for the upcoming period.

Out in the arena there are chances for you to get overpriced refreshments, stand in long lines to use the facilities, or just stay in your seat and watch the silly intermission games.

Some examples I've seen of silly intermission games are Fuego Pong (like quarters, but with soccer balls and large 5 gallon buckets), ice bowling where a player is put into a giant slingshot on the ice and hudled towards inflatable bowling pins, and the dress up game.

It's also during this time that the ice is resurfaced by a Zamboni to make it nice and clean for the next period.

If at the end of the third period the game is tied then you're in luck because you get free hockey, also known as Overtime. One thing to keep in mind is that the overtime rules during a regular season game are different than a postseason game.

Regular Season Overtime Rules

At the end of the third period there is a 1 minute 'intermission' and then a 5 minute overtime period starts. The overtime period will feature 3 skaters from each team as well as their goalie.

If a penalty occurs in Overtime (or is carried over from the third period) the period starts with four players on the power play team and 3 on the short handed team.1

Each team tries to score a goal first. If they do, then they win in overtime. If, at the end of 5 minutes of play, the score is still tied then a shootout happens.

In the shootout each team has 3 chances to score a penalty shot. Essentially a skater from each team has the opportunity to try and score a goal with only the goalie trying to prevent it. If at the end of the three rounds we're still tied, we keep sending out skaters to try and get that penalty shot until one team is victorious. The record for most rounds of a shoot out is 20 rounds in the NHL, and 16 rounds in the AHL.

Postseason Overtime Rules

Postseason overtime rules are a bit different. Basically you just keep adding 20 minute periods until someone scores. Once a team scores they have won that game. The longest overtime in NHL Postseason history went into the 6th overtime and was played in 1936 between the Detroit Red Wings and the Montreal Maroons. The longest AHL overtime was between the Charlotte Checkers and the Lehigh Valley Phantoms which went into a 5th overtime period. This game started at 7:03 pm local and didn't finish until almost 3:00 am local the next day!

In general most hockey games don't get past the first OT period. From The 2006 playoffs through to the 2024 playoffs there have only been 52 games that have gone into a second overtime period (out of 1312).

OK, you've got a few basics 'under your belt'. In the next part I'll try and answer the question, 'What should I watch?'.

  1. essentially it would be a short Overtime period and probably pretty boring ↩︎

How to Watch a Hockey Game - Three Rules

I've written a few times before about hockey. I love watching my local sports puck team1 and really wish more people watched it. So, I'm going to write a beginners guide to watching hockey so that you too, dear reader, can become an avid fan.

Hockey is a pretty fast paced game at the professional level. In the 90s Fox Sports had broadcast rights to hockey in the US and to help its viewers they had a glowing halo on the puck called FoxTrax which allowed fans to more easily find it. This practice was discontinued at some point, and I honestly think it was one of the better innovations that Fox Sports did and really wish that it would make a come back.

The Rules

As a beginner hockey observer there's only three rules that you really need to know to be able to follow the game.

  1. Offside2
  2. Icing
  3. Power Play / Penalty Kill

The Set up

The ice rink can be broken into 3 sections from the perspective of 1 team. Let's assume we have two teams, A and B. Let's root for team A.

Ice Hockey Rink

  1. The Defending zone - This is where team A's Goal is located. It starts right behind team A's goal and goes to the right toward the blue line
  2. Neutral Zone - This is the center of the ice between the two blue lines; it also contains a red line that is called 'Center Ice'
  3. The Attacking Zone - This is where team A are trying to score. It starts at the OTHER blue line and goes back behind Team B's goal

Offside

Offside is defined as ... actually that's not important. What is important to understand is that a player on the offense cannot enter their Attacking zone before the puck does. If they do, then that player is called Offside. When an Offside happens a face off takes place outside of the Attacking zone (i.e. in the Neutral Zone) where each team will try and gain control of the puck.

Icing

Icing, or icing the puck, is when a player in their half of the ice and shots the puck down the ice towards their Attacking zone and it is NOT touched by anyone before it passes the face off circles in the Attacking zone. When an icing occurs the puck is returned to the defending zone for a face off3. When an icing occurs the team that the icing is called on have to keep all of their players on the ice, that is, they can not send in any substitutions.

Power Play / Penalty Kill

The two rules above, when broken, result in a stoppage of play and a new face off for each team to try to gain control of the puck. Other rules, when broken, will result in a penalty4 which sees one, or more, players sent to the Penalty Box5. Penalties can either be minor, which result in a two minute penalty, or major, which typically result in a 5 minute penalty6.

When a team is on the Power Play they will have 1 or more extra skaters than the other team. The other team's 'missing' players will be in the Penalty Box. The Power Play team, with the advantage, will remain on that advantage until either they score OR the penalty expires. If a team scores while on the Power Play, they are said to have scored a Power Play Goal.

The team that has penalized players is said to be on the Penalty Kill. They are trying to 'kill' the advantage that the Power Play brings to the other team. If the team on the Penalty Kill scores a goal, it is called a Short-handed goal ... because they were short a person, i.e. short handed, when the goal was scored. In the National Hockey League (NHL), American Hockey League (AHL), and most other leagues when a short handed goal is scored the Penalty keeps going until time is over OR a goal is scored by the team on the Power Play. The Professional Women's Hockey Leagure (PWHL) has a rule (which I think is genius) which states that IF a team scores a short handed goal, the Power Play is over.7

In the next post I'll talk a bit more about game play.

  1. The Coachella Valley Firebirds ↩︎
  2. in hockey it is not pluralized like in American Football ... even though in American Football it's not pluralized either! ↩︎
  3. This does NOT apply when your team is on a Penalty Kill ↩︎
  4. I'll talk more about various penalties in future a post ↩︎
  5. it's a small room where players are sent to think about what they did ↩︎
  6. There are a few caveats here about game misconduct, but they're not important for an introductory primer ↩︎
  7. Now, there are lots of Nuances to the PP/PK write up above, but you don't need to understand them initially to enjoy hockey. ↩︎

An Argument to Realign the AHL

What is the AHL

The AHL, or American Hockey League, is a hockey minor league based in the US and Canada. It's widely considered to be the step right below the NHL which is the top Hockey League in North America.

There are 32 teams in the AHL, and 23 of them make the playoffs. The teams play for the Calder Cup.

What are the Calder Cup Playoffs?

The Calder Cup Playoffs are the name given to the AHL team vying for the Championship Calder Cup. The 2023 Calder Cup Playoffs started on April, 18 2023 with 14 teams playing in 7 different series while the other 9 all had byes, that is, they did NOT play in the first round.

One thing to note is that the first round is essentially a play in1 round of the playoffs, but it's not an evenly divided play-in.

The current format has round 1 with a best of Three Games, rounds 2 and 3 with a best of Five Games, and both the Conference Finals and Calder Cup Finals with a best of Seven Games.

Why Realign?

The ultimate goal is to enhance competitive balance and foster new rivalries, making the playoff race and outcomes more reflective of team performance throughout the season.

The current structure of the AHL divides the entire league into 2 conferences, and each conference has 2 divisions.

In the Eastern Conference, you have the Atlantic and North divisions. The Atlantic has 8 teams, while the North has 7.

Out in the Western Conference, you have the Pacific and Central division. The Pacific has 10 teams, while the Central has 7 teams.

Now an interesting thing about the playoffs is that the top 7 (of 10) teams from the Pacific make the playoffs, while the top 5 (of 7) teams from the North and Central make it. The Atlantic sends its top 6 (of 8) teams to the playoffs.

Each division will have a certain number of teams with a bye-round, that is they don't have the play in the first round.

In the North and Central three teams get a first-round bye, with only 2 teams playing in round 1. In the Atlantic three teams get a first-round bye with 4 teams playing in the first round.

And in the Pacific division, you have 6 teams playing in the first round with only ONE team getting a first-round bye.

So of the 23 teams that make the playoffs, 14 of them play in the first round, and of that 14, 6 come from the Pacific division.

Seems a bit off to me.

This also had the slightly embarrassing (for the AHL at least) aspect of seeing the second-best team in the entire league in the 2022-23 season (the Coachella Valley Firebirds) needing to win a Play-in round to make it into what might be considered the playoffs.

By the time the Calder Cup Playoffs had concluded last year, the Firebirds lost to the Hershey Bears in 7 games. It was the MOST exciting series that I will ever get to see in person, or on TV.

That being said, the Firebirds played 26 out of a possible 27 games during the playoffs last year. The Bears played in 20 out of a possible 24.

If the Firebirds would have had a first-round bye, like the Bears, they would have most likely still played in 23 out of 24 games (3 fewer games than what they actually played) BUT three games can make a huge difference!

I would like to make the case that realignment of the AHL, to a balanced set of divisions, and conferences is not only feasible, and easy, but in the best interests of the AHL.

Before exploring the realignment scenario, I'll outline the proposed changes. The realignment aims to balance the divisions and conferences, ensuring an equal number of teams in each division and a fairer playoff qualification process.

Additionally, if this realignment had happened last year, I believe that the outcomes could have been different (especially given the Firebird Colored Glasses I might be wearing).

There is a post on the AHL Site about realignment. Quoting the League President Scott Howson:

There’s no easy solution. I’m not saying it’ll never happen, but it’s not in the cards right now.

One item stated for a lack of realignment is, "Realignment would break up the Pacific cohort and likely force teams into the Central, and Howson does not see that as likely, given the additional travel burden that it could put on the division’s members."

I'm going to assume this is NOT the case. What I have below is from a "Does this seem like it might work?" perspective. 2

Realignment

With my rationale for the need for realignment of the way, let's get into the actual implementation of the realignment.

I built a Streamlit app to see what a potential realignment would look like that can be found here.

The idea would be:

  1. Move both Tucson and Colorado to the Central Divsiion to get the Pacific Division down to 8 team
  2. Move Grand Rapids from the Central Division (in Western Conference) to the Atlantic Division (in the Eastern Conference) to get the Central and Atlantic to 8

Impact of Realignment on the 2023 Calder Cup Finals

In the NHL there are 2 conferences with 2 divisions of 8 teams each. The playoffs get a total of 16 teams. The three top teams from each division, and then the top two teams from the Conference.

This means that round 1 has 16 teams playing in 8 different series and NO ONE gets a bye.

Let's imagine the 2023 Calder Cup Playoffs with realignment AND a similar style of playoff admission. One difference between the AHL and NHL I'd keep would be to have 5 games in round 1 and 2, and increase to 7 games in the Championship, versus the NHL which has 7 games in every round.

I list the teams below in their proposed (potentially new) division. The number next to the team is the total points each team had at the end of the 2022-23 regular season.

The Eastern Conference would have had the following seeding:

Atlantic Division

  • Providence (98)
  • Hershey (97)
  • Charlotte (86)

North Division

  • Toronto (90)
  • Syracuse (81)
  • Rochester (81)

Wild Card

  • Springfield (84)
  • Hartford (81)

The Western Conference would have had the following seeding:

Central Division

  • Texas (92)
  • Colorado (90)
  • Milwaukee (89)

Pacific Division

  • Calgary (106)
  • Coachella Valley (103)
  • Abbotsford (87)

Wild Card

  • Manitoba (84)
  • Iowa (79)

Eastern Conference Playoffs

Round 1 Best of Five games

In this section, we'll explore the first-round matchups, highlighting the top contenders and their paths to victory based on past performances and current strengths.

Starting in the Eastern Conference we would have the following round 1 matchups:

  • Providence (98) vs Hartford (81)
  • Toronto (90) vs Springfield (84)
  • Hershey (97) vs Charlotte (86)
  • Syracuse (81) vs Rochester (81)

To determine the winners I'm going to look at the playoffs last year and then make an educated best guess as to the winners of each series

Providence vs Hartford

Providence lost to Hartford in the Atlantic division semi-finals last year, 1-3 and I see no reason for that to change ... other than maybe Hartford wins in 3 instead of 4. But I'm going to keep it at Hartford wins 3-1

Toronto vs Springfield

Toronto and Springfield didn't play each other in the playoffs last year or in the regular season. Springfield lost to Hartford 2-0 in round 1 while Toronto had a first-round bye and defeated Utica 3-1 in the North division semi-finals. My guess is that Toronto would have won this series 3-1

Hershey vs Charlotte

Hershey defeated Charlotte in the Atlantic division semi-finals last year 3-1. Granted Charlotte had just played 3 games against Lehigh Valley and won that series 2-1, I still think that Hershey defeats Charlotte, only it takes all 5 games. Hershey wins 3-2

Syracuse vs Rochester

Syracuse lost 3-2 to Rochester. Same result this time around I would think

Round 2 Best of Five games

Based on the seedings for the first round, I believe that Hartford would hold a higher position than Rochester

  • Hershey (97) vs Rochester (81)
  • Toronto (90) vs Hartford (81)
Hershey vs Rochester

Hershey defeated Rochester 3-2 last year. I believe the outcome would be the same here (although this was in the Eastern Conference finals)

Toronto vs Hartford

Toronto and Hartford didn't play each other last year, though each team did get swept in the division finals. They played each other in the regular season only 2 times, each with the home team winning in OT. With Toronto getting the home nod, I'll extrapolate to say that Toronto wins in 5 games, 3-2

Round 3 (Eastern Conference Finals) Best of Seven

Toronto vs Hershey

Toronto played Hershey 2 times and lost both times. I think that a series like this would be closer, but Hershey comes out on top 4-2

Eastern Conference Champion Review

In this realigned AHL for the Calder Cup finals, Hershey has played 16 out of 17 games, going 10-6 to reach the Calder Cup Finals. When they actually reached the Calder Cup finals last year, they played only 13 games going 10-3 (playing an extra 3 games)

Providence (98)----|
                   |--Hartford (81)----|
Hartford (81)------|                   |
                                       |--Toronto (90)-----|
Toronto (90)-------|                   |                   |
                   |--Toronto (90)-----|                   |
Springfield (84)---|                                       |
                                                           |--Hershey (87)
Hershey (87)-------|                                       |
                   |--Hershey (87)-----|                   |
Charlotte (86)-----|                   |                   |
                                       |--Hershey (87)-----|
Syracuse (81)------|                   |
                   |--Rochester (81)---|
Rochester (81)-----|

Let's take a look out West next

Western Conference Playoffs

Round 1 Best of Five games

In the Western conference we would have had the following round 1 matchups:

  • Calgary (106) vs Iowa (79)
  • Texas (92) vs Manitoba (84)
  • Coachella Valley3 (103) vs Abbotsford (87)
  • Colorado (90) vs Milwaukee (89)

As with the Eastern Conference bracket to determine the winners I'm going to look at the playoffs last year and then make an educated best guess as to the winners of each series.

Calgary vs Iowa

Calgary didn't play Iowa at all in either the regular season or the postseason last year. Based on the final records, I think it's safe to say that Calgary wins this series, but I believe it's 3-1

Texas vs Manitoba

Texas played Manitoba 8 times in the regular season last year with Manitoba winning 6 of these games. There were several that went into OT which Manitoba won more often than not. I think this goes to 5 games, but Manitoba wins 3-2.

Coachella Valley vs Abbotsford

Coachella Valley and Abbotsford played 4 times, each winning two games. Given the disparity in total points at the end of the year, I think that Coachella Valley wins in five 3-2.

Colorado vs Milwaukee

Colorado and Milwaukee didn't play each other at all in the regular season. I think that this is an even match-up, but I give the edge to Colorado since they're the home team, winning 3-2.

Round 2 Best of Five games

  • Calgary (106) vs Manitoba (84)
  • Coachella Valley (103) vs Colorado (90)
Calgary vs Manitoba

Calgary wins this in 5, 3-2. They didn't play each other at all during the regular season, but I think that provincial pride forces the series to 5 games

Coachella Valley vs Colorado

Coachella Valley wins this in 5, 3-2. This is a repeat of the series last year. I believe that it goes the distance again.

Round 3 (Western Conference Finals) Best of Seven

Calgary vs Coachella Valley

Coachella Valley defeats Calgary 4-3

Coachella Valley and Calgary played each other in the Pacific Division Finals last year. It was a brutal series with Coachella Valley winning in game 5 in Overtime. I think that the same result comes out here going the distance.

Calgary (106)------|
                   |--Calgary (106)------|
Iowa (79)----------|                     |
                                         |--Calgary (106)----|
Texas (92)---------|                     |                   |
                   |--Manitoba (84) -----|                   |
Manitoba (84)------|                                         |
                                                             |--CV (103)
CV (103)-----------|                                         |
                   |--CV (103)-----------|                   |
Abbotsford (87)----|                     |                   |
                                         |--CV (103)---------|
Colorado (90)------|                     |
                   |--Colorado (90)------|
Milwaukee (89)-----|

Western Conference Champion Review

At the Calder Cup finals, Coachella Valley has played 17 out of 17 games, going 10-7. When they actually reached the Calder Cup finals last year, they played 19 games going 12-7. Two fewer games to get here.

Calder Cup Finals

In this matchup, Coachella Valley will have up to 4 home games, while Hershey will have up to 3.

Coachella Valley played in 2 fewer games in this scenario, while Hershey played in 3 more games, for a net difference of 5 games.

I think the first two games go as they did last year. Epic drubbings at Acrisure Arena by Coachella Valley over Hershey. I think that the 3 games4 in Hershey go 2-1 in favor of Hershey giving the Firebirds a chance to clinch on home ice in game 6 which they do.

Evaluating the Impact of Realignment: A Reflection on Competitive Balance and Missed Opportunities

Going through this exercise doesn't change the outcome of the 2023 Calder Cup Finals. And I don't want this to seem like a sour grapes sort of thing. The Hershey Bears won the Final game last year within the confines of the structure that was set up by the AHL. In that sense, they won it fair and square.

Also, I'm not sure if this realignment had been in place my predictions would have been correct necessarily.

What I think it does point out is an extreme disadvantage that the Pacific division faces in the playoffs. Last year the Coachella Valley Firebirds were the FIRST team west of Austin to make the Finals. They were also the first team to EVER play a playoff game in EVERY timezone that the AHL operates a team in.

Coda

I was bummed that the Firebirds lost in Game 7 last year. I wrote about it just a few days after it happened.

It was the most exciting sporting event I've ever seen, either in person or on TV. I'm not sure anything will ever be that intense and exciting.

I really wish they would have won, and this shows that they just might have been able to if the conference, divisions, and playoff seedings were a bit more balanced.

  1. preliminary round that occurs before the start of the official playoffs. It is typically used to determine who gets the last spots in the playoff ↩︎
  2. A full analysis is something I'll be looking at for another post in the future. There are lots of other items to look at like (1) Schedules, (2) Travel, and (3) Rivalries ↩︎
  3. Coachella Valley is abbreviated CV in some cases below to save space ↩︎
  4. In all honesty the 3 games in Hershey last year were games where the Firebirds seemed a bit tired. There was also some officiating that seemed a bit dubious (an offside that didn't get called that led to a goal that, IMO, shouldn't have counted) ↩︎

Firebirds Inaugural Season

On Wednesday June 21, 2023 the local sports puck team (i.e. Hockey), the Coachella Valley Firebirds hosted Game 7 of the Calder Cup Finals against the Hershey Bears.

There are sports writers that can write on how the series went, better than I can so I'll leave that to the pros. What I will talk about is why watching that game and seeing the Firebirds lose in Overtime hit me so hard.

I'm generally an introverted person. Even before the pandemic, I wasn't particularly fond of attending crowded events. The pandemic only intensified my preference for solitude. Suddenly, I found myself being advised to avoid social interactions altogether. As an introvert, the circumstances necessitating isolation weren't exactly ideal for me, but I did appreciate the fact that my family and I had to isolate.

However, after 2+ years of isolating from most everyone, being in large groups would bring out anxiety. And when I say large groups I mean like 10, maybe 15 people. On December 18th there was work holiday get together, the first one since the pandemic started. There were about 100 people in a mostly enclosed space and I did not do well with it. Super anxious, wore a mask the entire time, and generally ducked into the closet that also serves as my office more than once just to get away from people.

That same night was the home opener for the Firebirds at Acrisure Arena (due to construction delays their home arena opened 2 1/2 months after the start of the season). I didn't know it at the time, but it was a sell out (attendance of 10,087). This meant that I was going to a sporting event, in an enclosed arena with 10,000+ people. To say that I nearly lost my shit would be an understatement. The only thing that really got me to go was that the tickets I had purchased weren't cheap, and my wife and I were going with another couple friend.

That first home game was amazing. The Firebirds won 4-3 over the Tucson Roadrunners. The energy was amazing and I decided that I had to go to another game. And so I kept going. Again and again and again. I saw 34 games in person with an average attendance of 7,500.

I'd like to say that "just like that" my anxiety surrounding large indoor gatherings was gone, but it wasn't. It took me going to lots of hockey games to get through it.

So coming back to game 7 on Wednesday night. With less than 1 minute into the second period the Firebirds scored their second goal to go up 2-0. The crowd was the loudest I'd ever heard at Acrisure. Chants of "we want the cup" roared through the arena. It was unreal. And I sat there and realized that if it hadn't been for this team my anxiety surrounding large gatherings wouldn't have gone away for probably a very long time. And other than being a HUGE fan, I wanted the players, coaches, and team to win because they had helped me deal with something so personal. I won't ever be able to repay them for that, but my cheering them on to try and win the cup could maybe start.

And then the unthinkable happened. A penalty was called on the Firebirds and a Power Play goal was scored. Then less than 4 minutes later an even strength goal was scored and we were tied at 2 a piece.

The third period ended without any scorning by either team, and for only the second time in Calder Cup finals history, the first time since 1953, we were going to Overtime in a Game 7.

As we entered Overtime everyone in my section (107) was on their feet. We stood for the entire overtime period. Cheering, and screaming (honestly, I was still exhausted from the experience as I wrote this 2 days later).

About 2 minutes into the Overtime period Ryker Evan sent a shot on goal. From where I was sitting I could see the flight of the puck and my heart leapt as I thought it would find the back of the net ... but sadly it didn't. Within the first five minutes of overtime the Firebirds had outshot the Bears 5-0. It seemed like we were in control.

The next 10 minutes was some of the most intense back and forth hockey I'd ever seen.

With less than 4 minutes on the clock I thought, this might go into double overtime ... and then the unthinkable happened. The Firebirds defense was unable to clear a puck in their end, lots of players in front of the net, and just like that I see a puck flying over Joey's shoulder and past the cross bar, hitting the back of the net. The Bears player and their fans roared with joy, and suddenly a once deafening Acrisure was stunned into silence.

We lost. They won. The inaugural season was over. I stood in disbelief for a minute and then just sat down and stared across the arena at the Bears fans I could see that were losing their minds with joy. I wanted to cry. Some people around me did.

I stood up and looked over at our defensive end. The Firebirds players on the ice had taken a knee as they watched the Bears players celebrate. They don't show that part on TV. The defeated team looking sadly on as the victors celebrate. It was heartbreaking.

And then, in the middle of the celebration, the chants of "Let's go Firebirds" started. In short order, the fans were all saying it as loud as they could. An amazing season that didn't end the way we wanted it to, but we did our best to let the team know what they meant to us.

When I started writing this I thought maybe it was just me that needed something like this to get over some of the anxiety of large indoor gatherings, but maybe it was others. And those others at that game let the team know how much we appreciated them and what they did. This team will always hold a special place in the hearts of it's fans.

We didn't win it all this year, but there's always next year. Always.

Postlude

A friend of a friend of a friend works at a golf course called the 'Classic Club'. There were 3 players that were golfing the next day and they told this friend of a friend of a friend that the chants of "Let's go Firebirds" even after the loss meant so much to them.

ITFKH!!!

It’s time for Kings Hockey! A couple of years ago Emily and I I decided to be Hockey fans. This hasn’t really meant anything except that we picked a team (the Kings) and ‘rooted’ for them (i.e. talked sh*t* to our hockey friends), looked up their position in the standings, and basically said, “Umm ... yeah, we’re hockey fans.”

When the 2018 baseball season ended, and with the lack of interest in the NFL (or the NBA) Emily and I decided to actually focus on the NHL. Step 1 in becoming a Kings fan is watching the games. To that end we got a subscription to NHL Center Ice and have committed to watching the games.

Step 2 is getting notified of when the games are on. To accomplish this I added the games to our family calendar, and decided to use what I learned writing my ITFDB program and write one for the Kings.

For the Dodgers I had to create a CSV file and read it’s contents. Fortunately, the NHL as a sweet API that I could use. This also gave me an opportunity to use an API for the first time!

The API is relatively straight forward and has some really good documentation so using it wasn’t too challenging.

import requests
from sense_hat import SenseHat
from datetime import datetime
import pytz
from dateutil.relativedelta import relativedelta



def main(team_id):
    sense = SenseHat()

    local_tz = pytz.timezone('America/Los_Angeles')
    utc_now = pytz.utc.localize(datetime.utcnow())
    now = utc_now.astimezone(local_tz)

    url = 'https://statsapi.web.nhl.com/api/v1/schedule?teamId={}'.format(team_id)
    r = requests.get(url)

    total_games = r.json().get('totalGames')

    for i in range(total_games):
        game_time = (r.json().get('dates')[i].get('games')[0].get('gameDate'))
        away_team = (r.json().get('dates')[i].get('games')[0].get('teams').get('away').get('team').get('name'))
        home_team = (r.json().get('dates')[i].get('games')[0].get('teams').get('home').get('team').get('name'))
        away_team_id = (r.json().get('dates')[i].get('games')[0].get('teams').get('away').get('team').get('id'))
        home_team_id = (r.json().get('dates')[i].get('games')[0].get('teams').get('home').get('team').get('id'))
        game_time = datetime.strptime(game_time, '%Y-%m-%dT%H:%M:%SZ').replace(tzinfo=pytz.utc).astimezone(local_tz)
        minute_diff = relativedelta(now, game_time).minutes
        hour_diff = relativedelta(now, game_time).hours
        day_diff = relativedelta(now, game_time).days
        month_diff = relativedelta(now, game_time).months
        game_time_hour = str(game_time.hour)
        game_time_minute = '0'+str(game_time.minute)
        game_time = game_time_hour+":"+game_time_minute[-2:]
        away_record = return_record(away_team_id)
        home_record = return_record(home_team_id)
        if month_diff == 0 and day_diff == 0 and hour_diff == 0 and 0 >= minute_diff >= -10:
            if home_team_id == team_id:
                msg = 'The {} ({}) will be playing the {} ({}) at {}'.format(home_team, home_record, away_team, away_record ,game_time)
            else:
                msg = 'The {} ({}) will be playing at the {} ({}) at {}'.format(home_team, home_record, away_team, away_record ,game_time)
            sense.show_message(msg, scroll_speed=0.05)


def return_record(team_id):
    standings_url = 'https://statsapi.web.nhl.com/api/v1/teams/{}/stats'.format(team_id)
    r = requests.get(standings_url)
    wins = (r.json().get('stats')[0].get('splits')[0].get('stat').get('wins'))
    losses = (r.json().get('stats')[0].get('splits')[0].get('stat').get('losses'))
    otl = (r.json().get('stats')[0].get('splits')[0].get('stat').get('ot'))
    record = str(wins)+'-'+str(losses)+'-'+str(otl)
    return record


if __name__ == '__main__':
    main(26) # This is the code for the LA Kings; the ID can be found here: https://statsapi.web.nhl.com/api/v1/teams/

The part that was the most interesting for me was getting the opponent name and then the record for both the opponent and the Kings. Since this is live data it allows the records to be updated which I couldn’t do (easily) with the Dodgers programs (hey MLB ... anytime you want to have a free API I’m ready!).

Anyway, it was super fun and on November 6 I had the opportunity to actually see it work:

<iframe src="https://www.youtube.com/embed/AzdLSrA8wvU" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"></iframe>

I really like doing fun little projects like this.


Page 2 / 2