Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Call the website and load into our page variable
- $page = Invoke-WebRequest "http://www.accuweather.com/ajax-service/find-minutecast-location?query=norfolk,va&address=Norfolk,%20VA&lat=36.84682083129883&lon=-76.2850570678711&languageID=1"
- #Looking at the result via a brower I was able to locate the data chart about 2/3 of the way down
- #Doing a VERY quick regex, you can come up with the following
- $regex = [regex]'"time">(?<time>\d+\:\d+).+"type"><p>(?<rain>.+)</p>'
- #Take our regex, find the matches on the page and loop through them
- $results = $regex.Matches($page.Content) | % {
- # create a custom object with the results
- [pscustomobject]@{
- Time = $_.Groups[1]
- Rain = $_.Groups[2]
- }
- }
- # for now display the results in a table autosized to contents
- # $results | ft -AutoSize
- [bool]$willrain = $false
- $timerainstart = $null
- $timerainstop = $null
- $typeofrainstart = $null
- $typeofrainstop = $null
- Foreach ($res in $results){
- If ($res.Rain.Value -eq "No Precipitation")
- {
- If ($willrain -eq $true){
- if($timerainstop -eq $null){$timerainstop = $res.Time.Value}
- }
- }else{
- if ($willrain -eq $true){
- $timerainstop = $res.Time.Value
- $typeofrainstop = $res.Rain.Value
- }else{
- $timerainstart = $res.Time.Value
- $typeofrainstart = $res.Rain.Value
- $willrain = $true
- }
- }
- }
- If ($willrain -eq $false){
- Write-Host "Looks clear for the next two hours";
- }else{
- If($timerainstop){Write-Host "$typeofrainstart starting at $timerainstart and ending with $typeofrainstop at $timerainstop"
- }else{Write-Host "$typeofrainstart starting at $timerainstart - in 120 minutes - $res.Rain.Value - unknown stop time"}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement