PowerShell v2+ & Default Browser, 215 217 bytes
$l=date;for(){if(($x=([xml](iwr xkcd.com/rss.xml)).rss.channel.item[0]).pubdate-ge$l){if(($y=$x.description)-match'img src'){saps ($y-replace'<img src="'-replace'" .*')}else{echo "interactive comic"}}$l=date}
WARNING: Running this as-is will likely make Randall very mad at you, due to the high frequency of calls to the RSS feed ... so, y'know, don't do that. (See below for an alternate version that can be used in a one-off manner)
Sets the $l
ast time we displayed a comic to the result of Get-Date
. Then, enter an infinite for
loop.
Each iteration, we iwr
(alias for Invoke-WebRequest
) the RSS feed for the site. That's parsed as [xml]
(yes, PowerShell can cast as XML), and the .rss.channel.item[0]
thereof (i.e., the newest) is stored in $x
. If the .pubDate
is -ge$l
(i.e., newer than the last comic we showed), we have a new comic to display.
So, we first check the .description
field (saved in $y
), to see if it matches img src
. If so, we parse out the img from $y
, and feed that to saps
(alias for Start-Process
). Since it's a URI, this relies on Windows' default behavior for "executing" a URI, that is, it opens the default browser to that location. (If this is too cheaty, let me know and we can iwr
down the actual image and save it.)
Otherwise, we echo
out that we've got an interactive comic
.
In either case, we update our $l
date to "now" since we just displayed a comic.
Saved 7 bytes thanks to Matt for reminding me that http://
can be implied
"Safe" version that executes just once and displays the latest comic
$l=(date).AddDays(-3);if(($x=([xml](iwr http://xkcd.com/rss.xml)).rss.channel.item[0]).pubdate-ge$l){if(($y=$x.description)-match'img src'){saps ($y-replace'<img src="'-replace'" .*')}else{echo "interactive comic"}}
You can run this one safely to see how the logic works. It'll only execute once and only display the latest comic.
<img>
tag. \$\endgroup\$