PowerShell your world cup

A little Friday night fun here, of course the first thing i thought when i saw the below tweet from Will.I.Lam was, Ooooo that wouldnt take long to use in PowerShell.

image

And of course just 20 mins after finishing work I had a few functions, here is how you use them.

1. Go to the kimono website and sign up for an account, this will get you an APIkey, Click your name once you have logged in and select account.

2. Copy the API key and paste it below in the script and have fun!

The Functions

$global:APIkey = "YOUR-KEY-GOES-HERE-FROM-STEP-2"

Function Get-WorldCupPlayer ($Country) {
    If ($Country) {
        $TeamID = (Get-WorldCupTeam -Country $Country).id
        Invoke-WebRequest -Uri ("http://worldcup.kimonolabs.com/api/players?teamId=$($TeamID)&apikey=$($ApiKey)") | ConvertFrom-Json
    } Else {
        Invoke-WebRequest -Uri "http://worldcup.kimonolabs.com/api/players?apikey=$($ApiKey)" | ConvertFrom-Json
    }
}

Function Get-WorldCupTeam ($Country, $TeamID) {
    If ($Country) {
        Invoke-WebRequest -Uri ("http://worldcup.kimonolabs.com/api/teams?name=$($Country)&apikey=$($ApiKey)") | ConvertFrom-Json
    }
    If ($TeamID) {
        Invoke-WebRequest -Uri ("http://worldcup.kimonolabs.com/api/teams?id=$($TeamID)&apikey=$($ApiKey)") | ConvertFrom-Json
    }

    If (!$country -and !$TeamID) {
        Invoke-WebRequest -Uri "http://worldcup.kimonolabs.com/api/teams?apikey=$($ApiKey)" | ConvertFrom-Json
    }
}

Function Get-WorldCupStat {
    Invoke-WebRequest -Uri ("http://worldcup.kimonolabs.com/api/teams?sort=goalsFor,-1&apikey=$($ApiKey)") | ConvertFrom-Json
}

Bring on the World Cup Fun

#Display the best team in the World Cup

Get-WorldCupTeam -Country “England”

image

Get-WorldCupStat | Format-Table

image

Get-WorldCupPlayer | Format-Table

image

Get-WorldCupPlayer -Country “England” | Format-Table

image

#Who has scored the most goals in the Netherland team so far?

Get-WorldCupPlayer -Country “Netherlands” | Foreach { $_ | Where { $_.goals -gt 0 } | Select firstName, lastName, goals } | sort goals –Descending

image

#View the Logo of the team who is going to win
$logo = (New-Object System.Net.WebClient).DownloadFile(((Get-WorldCupTeam -Country “England”).logo), ($env:TEMP + “\Logo.png”))
Invoke-Item $env:TEMP\Logo.png

image

5 thoughts on “PowerShell your world cup”

  1. Ha ha, I was going to say “but who is going to win, Alan?” – but I see you’ve got that covered πŸ™‚

Leave a Reply