PoshCode Archive  Artifact [0462280cf1]

Artifact 0462280cf1fdefe99501470f01963caea68185f82115c8ab8c90f3739c3d0ca6:

  • File Get-2011SGScriptingScore.ps1 — part of check-in [5bc0876fa2] at 2018-06-10 13:13:20 on branch trunk — Function to retrieve score information for the 2011 Microsoft Scripting Games. (user: Mike Hammond size: 2862)

# encoding: ascii
# api: powershell
# title: Get-2011SGScriptingScore
# description: Function to retrieve score information for the 2011 Microsoft Scripting Games.
# version: 20.88
# type: function
# author: Mike Hammond
# license: CC0
# function: Get-2011SGScriptingScore
# x-poshcode-id: 2622
# x-archived: 2011-04-25T16:27:03
# x-published: 2011-04-21T14:55:00
#
#
Function Get-2011SGScriptingScore ([Parameter(Mandatory=$True)][STRING]$Contestant) {

   $WebClient = New-Object System.Net.WebClient

   $Results = $WebClient.DownloadString("https://2011sg.poshcode.org/Reports/TopUsers?filter=Beginner")+$WebClient.DownloadString

("https://2011sg.poshcode.org/Reports/TopUsers?filter=Advanced")

   $meIndex = $results.indexof($Contestant)

   if($meIndex -eq -1) {
      write-output "Contestant name `"$Contestant`" not found"
   } 
   
   else 
   
   {

      $myName = $results.substring($meIndex,$Contestant.Length).trim()
      $remainingtext = $results.substring($meIndex + $Contestant.length)
      $remainingtext = $remainingtext.substring($remainingtext.indexof(">")+1)
      $remainingtext = $remainingtext.substring($remainingtext.indexof(">")+1)
      $remainingtext = $remainingtext.substring($remainingtext.indexof(">")+1)
   
      $myscore = $remainingtext.substring(0,$remainingtext.indexof("<")).trim()
      $remainingtext = $remainingtext.substring($remainingtext.indexof(">")+1)
      $remainingtext = $remainingtext.substring($remainingtext.indexof(">")+1)
   
      $myScripts = $remainingtext.substring(0,$remainingtext.indexof("<")).trim()
      $remainingtext = $remainingtext.substring($remainingtext.indexof(">")+1)
      $remainingtext = $remainingtext.substring($remainingtext.indexof(">")+1)
   
      $myRatings = $remainingtext.substring(0,$remainingtext.indexof("<")).trim()

      write-output "Contestant `"$Myname`" has scored $MyScore points from $MyScripts scripts that have accumulated $MyRatings 

ratings"
   }

<#
.Synopsis
Retrieves Scripting Games score data for a given contestant

.Description
Retrieves HTML from the PoshCode.org site from both the beginning and advanced leaderboards and contatenates the full text output.  

The text is then searched for the name of the contestant, and relevant data is retrieved using horrible, horrible text matching code.

.Parameter Contestant
Contestant is a String parameter used to identify the participant in the scripting games.  This is a case-insensitive match against 

the name under which the user registered for the Scripting Games

.Example
Get-2011SGScriptingScore "ScriptingWife"
Contestant "ScriptingWife" has scored 20.88 points from 9 scripts that have accumulated 24 ratings

.Example
Get-2011SGScriptingScore "NoSuchPlayer"
Contestant name "NoSuchPlayer" not found
#>

}