admajonse / nhl-bot Goto Github PK
View Code? Open in Web Editor NEWA Twitter bot that posts when events occur in Colorado Avalanche games.
License: MIT License
A Twitter bot that posts when events occur in Colorado Avalanche games.
License: MIT License
We should include the strength of the scoring team when a goal event is tweeted. Even strength tweets are fine as-is. See get_goal_string
in printer.py
.
Goals aren't always posted with full details right away. Sometimes you just get the goal scorer and then the event is updated to include the assists after the fact. We need some way to detect when an event has been updated.
One way to handle this would be to post the goal with the goal scorer initially and then reply to the tweet with the full goal details (IE: who got the assists, etc).
This would require an update to the way we handle events - currently we only process new events, once an event has shown up and been processed, it's ignored. Maybe we could cache a copy of the last JSON data, compare previous records to the updated data and determine whether any previously processed events have been updated?
Shootout attempts are just treated as shot or goal events, but they have their period
set to SHOOTOUT
. We should log all events where period is set to the shootout. These should be special events and post the score of the shootout so far if possible.
Sometimes we have tweets like this:
https://twitter.com/avalanche_bot/status/1516969975235371012
Josh Manson
2 minute minor for minor
This likely means that the secondaryType
is initially just populated with the severity and then the actual penalty is added after the fact. We should verify that there is an actual penalty call prior to tweeting. If there's not, we can delay the tweet, similar to the way that we delay when the penalty taker is not present.
When we run in a container, the system uses UTC time (midnight UTC corresponds to 8:00 PM eastern). This means that when we start the container and query the date to determine if there's a game today, we may actually be querying the wrong date.
The NHL API uses UTC for time stamps in their game data, however, the "date" field in a schedule query considers games that start after midnight UTC to still be part of the previous day.
I think the simplest way to deal with this is to simply apply an offset when checking for games on a given date. The latest we ever see a game start is around 10:30 PM EST (or 3:30 UTC on the next day). To be safe, we could simply convert the UTC time to EST prior to getting the date.
Some game events (ie: pulling the goalie) aren't displayed as events in the allPlays
list, but they do appear in the line score. For example, whether or not a goalie is pulled is a boolean in the line score. We should add some sort of handler that is triggered when this value in the line score changes.
Tweets for penalty events should indicate whether any existing penalties are still active and what the strength is post-penalty.
The printer doesn't really need to be responsible for tweeting. Lets just have it return strings with tweet text and we can tweet from somewhere else, thereby removing the dependency on tweeter.py
.
We should be using GitHub workflows to automatically build and run the docker container and ensure that the bot is functioning correctly. The workflow should run any unit tests (once I get around to writing them). Change requests that aren't functional should be rejected.
Currently we only process events that have not been processed previously (IE: the event ID is greater than the last event that was processed). There is also a time-based check (currently set to three minutes, but I've been experimenting with this a bit). This time-based check is mainly intended to reduce the amount of spam created when we start the bot mid-game. In this case, last_event
is initialized to 0 and so we'll process every event that has occurred in the game so far. A better way to handle this would be to silently process all previous events without tweeting and set last_event
to the latest event and then start regular processing from there. This would allow us to remove the time-based check completely and only process new events.
This is pretty rare obviously, but when a game is played at some venue other than the home team's arena, we post the wrong location in the game day and period start/finish tweets. Right now we're just retrieving the venue data from the home team's info record, but maybe there's some sort of game data that we can pull from instead? Needs a bit of investigation of the API, but this should presumably be a quick fix.
Not sure if they've added this to the API this season or it was just rare enough to miss. There's an event that occurs when a shootout ends called Shootout Complete
. We should handle this (even if just to throw it away). Right now it's raising an exception.
We don't necessarily need to post a tweet during all game events, but the bot should be aware of them and capable of handling them if the printer object defines behaiviour for this event.
The current set of events was taken from a single game. This game did not include overtime or a shootout. I'm pretty sure there will be some special event types that only occur during OT/shootout (ie: a shootout attempt). The game also didn't feature a penalty shot. There are probably other events that haven't occurred to me here.
We need to determine the full set of possible events and handle all of them in some way (even if they're just silently ignored, or logged without a tweet).
When the game ends, it is supposed to sleep until the following day at noon. This mostly works because most games end on the same date that they started, but for late games (ie: 9:30 - 10:30 PM EST start time), the game will sometimes end after midnight. When this happens, the bot will sleep until the after that, which could mean that we miss a game. It's pretty unlikely that you're going to have a game that ends after midnight and a game the next day, but we should make sure this works just to be safe. The simplest solution would be to record the game start time and wait until midnight on the day following the start time (rather than the end time as we do now).
The bot seems to think that all the shootout attempts are the same goal and keeps reporting new goals as goalscorer changes (ie: "The goal is now being awarded to" replies). This is likely related to the new method of identifying goal events (some sort of key that uses the period and time of the goal) - all goals in the shootout likely have the same ID.
We need a way to distinguish the goals in a shootout and then they should start to report correctly again.
The NHL API provides the ability to only return updates to the feed that have occurred after a give time. This is a good way to stop repeatedly retrieving and processing events that have already been dealt with. We should update the live feed data request to use this instead of the base live feed.
https://statsapi.web.nhl.com/api/v1/game/ID/feed/live/diffPatch?startTimecode=yyyymmdd_hhmmss
We should really include why they're challenging the play. The problem is that this information seems to be in the stoppage event that occurs prior to this one. Getting data from multiple events is going to be difficult with the current setup.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.