Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Call the website and load into our page variable
  2. $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"
  3.  
  4. #Looking at the result via a brower I was able to locate the data chart about 2/3 of the way down
  5. #Doing a VERY quick regex, you can come up with the following
  6. $regex = [regex]'"time">(?<time>\d+\:\d+).+"type"><p>(?<rain>.+)</p>'
  7.  
  8. #Take our regex, find the matches on the page and loop through them
  9. $results = $regex.Matches($page.Content) | % {
  10. # create a custom object with the results
  11. [pscustomobject]@{
  12.     Time  = $_.Groups[1]            
  13.     Rain  = $_.Groups[2]
  14. }
  15. }
  16. # for now display the results in a table autosized to contents
  17. # $results | ft -AutoSize
  18. [bool]$willrain = $false
  19. $timerainstart = $null
  20. $timerainstop = $null
  21. $typeofrainstart = $null
  22. $typeofrainstop = $null
  23. Foreach ($res in $results){
  24. If ($res.Rain.Value -eq "No Precipitation")
  25. {
  26.     If ($willrain -eq $true){
  27.         if($timerainstop -eq $null){$timerainstop = $res.Time.Value}
  28.     }
  29. }else{
  30.     if ($willrain -eq $true){
  31.         $timerainstop = $res.Time.Value
  32.         $typeofrainstop = $res.Rain.Value
  33.     }else{
  34.         $timerainstart = $res.Time.Value
  35.         $typeofrainstart = $res.Rain.Value
  36.         $willrain = $true
  37.     }
  38. }
  39. }
  40. If ($willrain -eq $false){
  41.     Write-Host "Looks clear for the next two hours";
  42. }else{
  43.         If($timerainstop){Write-Host "$typeofrainstart starting at $timerainstart and ending with $typeofrainstop at $timerainstop"
  44.     }else{Write-Host "$typeofrainstart starting at $timerainstart - in 120 minutes - $res.Rain.Value - unknown stop time"}
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement