Skip to content

Instantly share code, notes, and snippets.

@nyanhp
Created June 22, 2018 07:36
Show Gist options
  • Save nyanhp/6a78904550fa3b57b2434a6e5fdec806 to your computer and use it in GitHub Desktop.
Save nyanhp/6a78904550fa3b57b2434a6e5fdec806 to your computer and use it in GitHub Desktop.
Checks for 2018 world cup results
# Install module for Toast Notifications
if (-not (Get-Module BurntToast -ListAvailable))
{
Install-Module BurntToast -Scope CurrentUser -Force
}
# Create path for state file
if (-not (Test-Path $env:APPDATA\Fuppes))
{
[void] (New-Item -ItemType Directory -Path $env:APPDATA\Fuppes)
}
# /matches/current returns $Null when no match is active, otherwise returns JSON content
$match = Invoke-RestMethod -Method Get -uri http://worldcup.sfg.io/matches/current -ErrorAction SilentlyContinue
$lastState = Get-Content $env:APPDATA\Fuppes\currentmatch.json -Raw -ErrorAction SilentlyContinue | ConvertFrom-Json
# Compare that stuff
if ($match -and ($match.'home_team'.goals -gt $lastState.'home_team'.goals) -and (($match.'away_team'.goals -gt $lastState.'away_team'.goals)))
{
$hometeam = $match.'home_team'
$awayteam = $match.'away_team'
$msg = '{0} - {1} {2}:{3} ({4})' -f $hometeam.code, $awayteam.code, $hometeam.goals, $awayteam.goals, $match.time
New-BurntToastNotification -Text 'GOOOOAAAL!', $msg
}
# Write new state file
$match | ConvertTo-Json -Depth 10 | Out-File -FilePath $env:APPDATA\Fuppes\currentmatch.json -Force -Encoding utf8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment