Monday, February 19, 2007

Keeping track of my 2007 Scripting Games score

As I mentioned a few times before, I'm participating in the 2007 Microsoft Scripting Games.  I've submitted all my 10 answers, and am just waiting for them to be scored.

To keep track of my scores "in the background", I've decided to use a combination of the out-gauge cmdlet from PowerGadgets, and the new write-speech cmdlet from Sapien PrimalToys.

So, I have a graphical display, and a voice telling me every 15 minutes what my score is.

Here's the graphical display:

Here's the script borrowed heavily from a posting by /\/\o\/\/ in the PowerShell newsgroups:

$wc = new-Object System.Net.WebClient
$nl = $wc.DownloadString("$url")
$r = [regex]'l">(.*?)</p'
$m = $r.Matches($nl)
$l = $m |% {$_.groups[1].value}
$list = @()
foreach ($i in 13..($l.count -1) ) {
$Record = new-Object -typename System.Object
$Record | add-Member -memberType noteProperty -name Name -Value $m[$i].groups[1].value
[void] $foreach.MoveNext()
$Record | add-Member -memberType noteProperty -name Country -Value $m[$foreach.current].groups[1].value
1..10 |% {[void] $foreach.MoveNext();$Record | add-Member -memberType noteProperty -name "E$_" -Value $m[$foreach.current].groups[1].value}
[void] $foreach.MoveNext();$Record | add-Member -memberType noteProperty -name "Total" -Value $m[$foreach.current].groups[1].value
$list += $record
$score=$($list | ?{$ -eq "Marco Shaw"} | %{$_.Total})
write-speech "Games score is $score"

[end script]

Here's how I call it:

21> games.ps1|out-gauge -refresh 00:15:00

I'm using a cool refresh feature of the PowerGadget cmdlet that will automatically call the PowerShell script every 15 minutes to cause it to run again.