Archive

Posts Tagged ‘RWC’

Who fancies knowing when the rugby is on?

September 1st, 2015 No comments

Been messing around with some regex for some boring work related consumption of poorly constructed data – when I thought why not do something useful?

Rugby world Cup is around the corner – let’s make the schedule accessible from my Powershell session

(be warned, this was a quick and nasty – no comments, no instructions)

 

</pre>
Function Get-RugbySchedule
{
$fixturesXML = (invoke-webrequest -uri "http://www.ultimaterugby.com/match/list").ParsedHtml.body.innerHTML
$maincontent = $fixturesXML -split "main-content" | select -skip 1 -first 1

$items =  $maincontent | Select-String '(?s)(<DIV class=match-item.*?</SPAN></DIV></DIV>)' -AllMatches

$item = $items.matches[1].Value
$out = @()
foreach($item in $items.Matches.Value)
{
$ret = "" | select Detail, HomeTeam, AwayTeam, HomeScore, AwayScore, Status, Kickoff, Date, Venue, Tournament
$teams = ($item | Select-String '(?<=class=team-name>).*?(?=</SPAN>)' -AllMatches).Matches
if($teams.count -eq 2)
{
$ret.Hometeam = $teams[0].Value
$ret.AwayTeam = $teams[1].Value
$scores =  ($item | Select-String '(?<=(<SPAN class=score>|<SPAN class="score win">)).*?(?=</SPAN>)' -AllMatches).Matches
if($scores.Count -eq 2)
{
$ret.HomeScore =$scores[0].value
$ret.AwayScore = $scores[1].Value
}

}

$ret.Status = ($item | Select-String '(?<=<META content=)(.*?)(?=itemprop="eventStatus">)' -AllMatches).Matches[0].Value.Replace('"',"")
$ret.Detail = ($item | Select-String '(?<=<META content=)(.*?)(?=itemprop="name">)' -AllMatches).Matches[0].Value.Replace('"',"")

$kickoff = ($item | select-string '(?<=<DIV class=kickoff>).*?(?=</DIV>)').Matches.Value
$ret.Kickoff = ($kickoff | Select-String '([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]').Matches.Value
$ret.Date = ($kickoff | select-string '(?<=<SPAN class=date>)(.*?)(?=</SPAN>)').Matches.Value

$locationInfo =  ($item | Select-String '(?s)(?<=itemprop="location").*?(?=</DIV>)' -AllMatches).Matches.Value
$ret.Venue = ($locationInfo | select-string '(?<=>)(([a-zA-Z0-9_ ])+?)(?=<)').Matches.Value

$details = ($item | select-string '(?<=<DIV class=tournament>).*?(?=</DIV>)').Matches.Value
$ret.Tournament = ($details | select-string '(?<=>)(([a-zA-Z0-9_ ])+?)(?=<)').Matches.Value
$out += $ret
}
return $out
}

Categories: Powershell Tags: ,