This is the code part of a birthday present which purpose is to be a live score updater for a specific team (LIF in this case).
It checks for when TARGET_TEAM
scores in SHL, and when they do, exec given command by GOAL_ON_CMD
, then GOAL_OFF_CMD
. In this case - turn USB on/off which make the blue rotating light be on/off.
- A node app is using Sportfåne to check for live goals.
- See .env.example for all envs used.
- A python script that checks for a button-press to manually toggle the light.
The code have 2 recursive loops that should make it run for all games automatically.
Sort of this:
The starting point of the app
- At startup check if there is any
game
fortoday
- if
game
:- launch
gameLoop
- launch
- if not:
- wait
until 12:00 next day
- restart
mainLoop
- wait
- fetch
game
information - if game ended:
- return
game_ended
tomainLoop
- return
- if
live
:- check for new scores from
TARGET_TEAM
- wait
POLL_TIME
- restart
gameLoop
- check for new scores from
- if not
live
:- wait
30 seconds
. - if more than 2 hours after
start_date_time
- return
game_not_started
tomainLoop
- return
- if not
- restart
gameLoop
.
- restart
- wait
Note
SHL killed their open API without any notice neither before nor after. Not cool SHL. Not cool._
LEGACY app_shl.js
DETAILS DOWN BELOW.
- A node app is using SHL Open API to check for live goals.
- See .env.example for all envs used.
- A python script that checks for a button-press to manually toggle the light.
The code have 3 recursive loops that should make it run for all future seasons automatically.
The starting point of the app.
- check for the current
season
. (named after the year it started in the API) - fetch
games
for theseason
. - if
games
:- launch
SeasonLoop
.
- launch
- if not:
- wait
24 hours
. - restart
mainLoop
.
- wait
- waits for
start_date_time
of next game. - launch
GameLoop
whenstart_date_time
have passed. - waits 15 minutes after game ended.
- fetch
games
for theseason
. - if more games for the season:
- restart
seasonLoop
.
- restart
- if not:
- end
seasonLoop
.
- end
- fetch detailed
gameReport
information - if game ended:
- return
game_ended
.
- return
- if
live
:- check for new scores from
TARGET_TEAM
- if period 1 or 2 ended:
- wait
15 minutes
- wait
- if not:
- wait
POLL_TIME
- wait
- restart
gameLoop
- check for new scores from
- if not
live
:- wait
15 seconds
. - if more than 2 hours after
start_date_time
- return
game_not_started
.
- return
- if not
- restart
gameLoop
.
- restart
- wait