shl-saftblandare

shl-saftblandare

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.

How?

  • A node app is using Sportfåne to check for live goals.
  • 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:

mainLoop

The starting point of the app

  • At startup check if there is any game for today
  • if game:
    • launch gameLoop
  • if not:
    • wait until 12:00 next day
    • restart mainLoop

gameLoop

  • fetch game information
  • if game ended:
    • return game_ended to mainLoop
  • if live:
    • check for new scores from TARGET_TEAM
    • wait POLL_TIME
    • restart gameLoop
  • if not live:
    • wait 30 seconds.
    • if more than 2 hours after start_date_time
      • return game_not_started to mainLoop
    • if not
      • restart gameLoop.

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.

How?

  • A node app is using SHL Open API to check for live goals.
  • 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.

mainLoop

The starting point of the app.

  • check for the current season. (named after the year it started in the API)
  • fetch games for the season.
  • if games:
    • launch SeasonLoop.
  • if not:
    • wait 24 hours.
    • restart mainLoop.

seasonLoop

  • waits for start_date_time of next game.
  • launch GameLoop when start_date_time have passed.
  • waits 15 minutes after game ended.
  • fetch games for the season.
  • if more games for the season:
    • restart seasonLoop.
  • if not:
    • end seasonLoop.

gameLoop

  • fetch detailed gameReport information
  • if game ended:
    • return game_ended.
  • if live:
    • check for new scores from TARGET_TEAM
    • if period 1 or 2 ended:
      • wait 15 minutes
    • if not:
      • wait POLL_TIME
    • restart gameLoop
  • if not live:
    • wait 15 seconds.
    • if more than 2 hours after start_date_time
      • return game_not_started.
    • if not
      • restart gameLoop.