get-cricscore.ps1

#########################################################################################################
##### LiveScore feed from cricbuzz.com,Script crated by pr_prakash78@outlook.coom/prax78@gmail.com#######
#######This powershell script will work on all Powershell versions#######################################
#########################################################################################################
<#PSScriptInfo
 
.VERSION 1.0
 
.GUID 0b4a595b-8043-4b3a-9fff-c82fd5fca3c3
 
.AUTHOR pr_prakash78@outlook.com
 
.COMPANYNAME
 
.COPYRIGHT Free
 
.TAGS
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>


<#
 
.DESCRIPTION
 This script fetches Live Cricket score updates from CricBuzzAPI
 
#>
 
Clear-Host
write-host -ForegroundColor DarkMagenta -BackgroundColor DarkYellow "Connecting to Cricbuzz.com"
$cntr=0
$ping=New-Object System.Net.NetworkInformation.Ping

try
{
if($ping.Send("cricbuzz.com").Status -eq "Success")
{

clear-host

write-host -ForegroundColor DarkMagenta -BackgroundColor DarkYellow "Connection to Cricbuzz established,Score will be updated shortly"

$mailxmlstore="$($env:USERPROFILE)\documents\crickscore"

if(!(Test-Path $mailxmlstore))
{
$mailxmlstore=New-Item -ItemType Directory $mailxmlstore

}


$request = [System.Net.WebRequest]::Create("http://synd.cricbuzz.com/j2me/1.0/livematches.xml")
$request.Method="Get"
$response = $request.GetResponse()
$requestStream = $response.GetResponseStream()
$readStream = New-Object System.IO.StreamReader $requestStream
$data=$readStream.ReadToEnd()
$results = [xml]$data
$results.mchdata.match|ForEach-Object{$_.outerxml|ft -AutoSize -Wrap -HideTableHeaders|Out-File "$($mailxmlstore)\$($_.id).xml" }

$xmlfiles=Get-Item "$($mailxmlstore)\*.xml"|select fullname
foreach($xmlf in $xmlfiles)
{
[xml]$xmlreader=Get-Content $xmlf.fullname
if(($xmlreader.match.state.mchState -ne "Result") -and ( $xmlreader.match.state.mchState -ne    "preview"))
{

$cntr++
$MatchStatus=$xmlreader.match.state.status
$TeamA=$xmlreader.match.mscr.btTm.sName
$ScoreA="{0} {1}/{2} in Overs {3}" -f  $xmlreader.match.mscr.btTm.sName, $xmlreader.match.mscr.btTm.Inngs.r,$xmlreader.match.mscr.btTm.Inngs.wkts,$xmlreader.match.mscr.btTm.Inngs.ovrs
$TeamB=$xmlreader.match.mscr.blgTm.sName
$ScoreB="{0} {1}/{2} in Overs {3}" -f $xmlreader.match.mscr.blgTm.sName,$xmlreader.match.mscr.blgTm.Inngs.r,$xmlreader.match.mscr.blgTm.Inngs.wkts,$xmlreader.match.mscr.blgTm.Inngs.ovrs

$TeamAstr="$($TeamA) has scored $($scoreA)"
$TeamBstr="$($TeamB) has scored $($scoreB)"
write-host -ForegroundColor DarkMagenta -BackgroundColor Yellow   "Cricket update courtesy Cricbuzz.com,Script Created by Pr_prakash78@outlook.com"
write-host "========================================================================================="
write-host -ForegroundColor magenta -BackgroundColor cyan "Match Number :: $($cntr) on $($xmlreader.match.Tme.Dt)"
write-host "========================================================================================="
write-host -ForegroundColor magenta -BackgroundColor black  "$($xmlreader.match.srs) : $($xmlreader.match.mchDesc) : $($xmlreader.match.vcity): $($xmlreader.match.grnd)"
$dt=New-Object System.Data.DataTable
$d1=$dt.Columns.add("MatchStatus")
$d1=$dt.Columns.add("Team-A")
$d1=$dt.Columns.add("Team-B")
$d1=$dt.rows.add($MatchStatus,$ScoreA,$ScoreB)

$d1|ft -Wrap
write-host "========================================================================================="
}
elseif($xmlreader.match.state.mchState -eq "preview")
{
write-host "========================================================================================="
write-host -ForegroundColor magenta -BackgroundColor black "Upcoming Matches on $($xmlreader.match.Tme.Dt) :: $($xmlreader.match.mchDesc)"
write-host "========================================================================================="
}
}
Remove-Item -Path $mailxmlstore -Force -Recurse
}
}
catch {

write-host -ForegroundColor Red -BackgroundColor Yellow "Unable to reach Cricbuzz.com,check netconnections" 
}