alias cnnrss {
var %e = echo -ac info * /cnnrss:, %tmp, %cat, %url
if ($isid) { %e can only be used as a command. | return }
tokenize 44 $(,,$regsub($1-,/\s*(?=\54)|(?<=\54)\s*/g,,%tmp)) %tmp
if ($1 !isnum 1-) { %e must specify number of recent headlines. | return }
var %categories = Top Stories,World,Africa,Americas,Asia,Europe,Middle East,Us, $+ $&
World Business,Technology,Science and Space,Entertainment,Sport,Football,Travel,Most Recent
if (!$istok(%categories,$2,44)) {
tokenize 44 $sorttok(%categories,44)
%e incorrect category specified - Possible categories:
echo -a $*
return
}
if ($2 == middle east) %cat = _meast.rss
elseif ($2 == science and space) %cat = _space.rss
elseif ($2 == world business) %cat = _business.rss
elseif ($2 == top stories) %cat = .rss
else %cat = _ $+ $2.rss
%url = http://rss.cnn.com/rss/ $+ $iif($2 == most recent,cnn_latest.rss,edition $+ %cat)
var %t = $ticks, %rss = rss $+ %t, %nodecol = nodecol $+ %t, %item = item $+ %t
var %children = children $+ %t, %cmd = $iif($3,$3,echo -a)
.comopen %rss Msxml2.DOMDocument
if ($comerr) { %e COM Error | return }
%tmp = $com(%rss,async,4,bool,false)
%tmp = $com(%rss,load,1,bstr*,%url)
.comclose %rss $com(%rss,selectnodes,1,bstr*,/rss/channel/item,dispatch* %nodecol)
var %i = 0, %ii = $comval(%nodecol,0)
while (%i < $1) && (%i <= %ii) {
%tmp = $com(%nodecol,item,1,uint,%i,dispatch* %item)
inc %i
if ($com(%item)) {
.comclose %item $com(%item,childnodes,3,dispatch* %children)
if ($com(%children)) {
%cmd %i - $comval(%children,1,text) ** $deltok($comval(%children,2,text),-1,63)
.comclose %children
}
}
}
.comclose %nodecol
}