NHL Live score for TouchBar

Here is a widget that displays the current score of a hockey game if your team is playing!
Copy and paste the code and simply change the TEAM_NAME. This as in no way been tested and I've been working on this for less than an hour, but it works for now, for me so why not share :grinning:!

Screenshots

Code

set TEAM_NAME to "Canadiens"

set myTeam to my GetTeam(TEAM_NAME)
set live to IsLive(myTeam)
set game to getGame(myTeam)


return (getHomeScore(game) as string) & " - " & getAwayScore(game) & "
" & getHomeName(game) & " - " & getAwayName(game)

on getHomeScore(TheGame)
	return score of home of teams of TheGame
end getHomeScore

on getHomeName(TheGame)
	return |name| of team of home of teams of TheGame
end getHomeName

on getAwayScore(TheGame)
	return score of away of teams of TheGame
end getAwayScore

on getAwayName(TheGame)
	return |name| of team of away of teams of TheGame
end getAwayName

on getGame(TheTeam)
	return item 1 of games of item 1 of |dates| of nextGameSchedule of TheTeam
end getGame

on IsLive(TheTeam)
	try
		if (abstractGameState of status of item 1 of games of item 1 of |dates| of nextGameSchedule of TheTeam) is equal to "Live" then
			return true
		else
			return false
		end if
	end try
	return false
end IsLive

on GetTeam(theTeamName)
	tell application "JSON Helper"
		set teamsData to fetch JSON from "https://statsapi.web.nhl.com/api/v1/teams?expand=team.schedule.next"
		set TheTeam to null
		
		set theIndex to 1
		set allTeamNames to ""
		repeat count of teams of teamsData times
			
			if teamName of item theIndex of teams of teamsData contains theTeamName then
				set TheTeam to item theIndex of teams of teamsData
			end if
			
			set theIndex to theIndex + 1
		end repeat
	end tell
	
	if TheTeam is null then
		error "Impossible to find team " & theTeamName
	end if
	
	return TheTeam
end GetTeam

Hi, nice job :slight_smile: can we do that with football?