Texting Yourself Sports Alerts with PowerShell
Friday, 21 February 2014
You've probably been in the situation of wanting to alert yourself when any update happens to a sports game, UPS package tracking status, or something else.
By combining Invoke-WebRequest's beautiful support for HTML parsing with Send-MailMessage's ability to send email messages - this becomes incredibly easy and useful.
(Note: this script also uses Watch-Command, a script from the PowerShell Cookbook.)
001
002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 |
$content = ""
while($true) { Watch-Command -ScriptBlock { ## Fetch the current box score for the game $r = Invoke-WebRequest http://www.tsn.ca/MENS_WORLD/scores/boxscore/?id=2388586 ## The score is in a DIV with the class 'boxScoreBg', almost certainly different ## Extract out what text you care about $SCRIPT:content = (@($result)[0].innerText -split "`r`n" | ? { $_ })[5.. ## And use that to monitor } -UntilChanged -DelaySeconds 30 ## Every cell provider has an email address that you can send to To = "[email protected]" From = "[email protected]" Subject = "Hockey Score Update" Body = $SCRIPT:content SmtpServer = "mysmtpserver" } Send-MailMessage @params } |