This is a script made by Scakk when I asked around on the forum. I find it usefull so i post it here.
Triggers :
!cnn help
!cnn sports, us, world, topstories, living, travel, showbizz, health, space, tech, politics, crime, money, recent
!cnn # (1 to 10) gives you a description and link to those full stories.
Changed it up to include many news feeds, not only world news feeds like before. This way, you get access to 14 news feeds
on *:text:!cnn *:#: {
if ($2 isnum && $2 >= 1) { set %cnnstory $round($2,0) }
if ($2 == sports) { set %cnnstory All | set %feed /rss/si_topstories.rss }
elseif ($2 == us) { set %cnnstory All | set %feed /rss/cnn_us.rss }
elseif ($2 == world) { set %cnnstory All | set %feed /rss/cnn_world.rss }
elseif ($2 == topstories) { set %cnnstory All | set %feed /rss/cnn_topstories.rss }
elseif ($2 == living) { set %cnnstory All | set %feed /rss/cnn_living.rss }
elseif ($2 == travel) { set %cnnstory All | set %feed /rss/cnn_travel.rss }
elseif ($2 == showbizz) { set %cnnstory All | set %feed /rss/cnn_showbiz.rss }
elseif ($2 == health) { set %cnnstory All | set %feed /rss/cnn_health.rss }
elseif ($2 == space) { set %cnnstory All | set %feed /rss/cnn_space.rss }
elseif ($2 == tech ) { set %cnnstory All | set %feed /rss/cnn_tech.rss }
elseif ($2 == politics) { set %cnnstory All | set %feed /rss/cnn_allpolitics.rss }
elseif ($2 == crime) { set %cnnstory All | set %feed /rss/cnn_crime.rss }
elseif ($2 == money) { set %cnnstory All | set %feed /rss/money_latest.rss }
elseif ($2 == recent) { set %cnnstory All | set %feed /rss/cnn_latest.rss }
elseif ($2 == help) { notice $nick triggers are sports, us, world, topstories, living, travel, showbizz, health, space, tech, politics, crime, money, recent
notice $nick type !cnn sports for sports news, !cnn us for USA news, etc. Then type !cnn 1 to 10 for more info
/halt }
set %cnnchan $chan
sockopen CNN rss.cnn.com 80
}
on *:sockopen:CNN: {
sockwrite -n $sockname GET %feed HTTP/1.1
sockwrite -n $sockname Host: rss.cnn.com
sockwrite -n $sockname Connection: close
sockwrite -n $sockname $crlf
}
on *:sockread:CNN: {
sockread %cnntemp
if (<title> isin %cnntemp) { inc %tt 1 | set %cnntitle $+ %tt $nohtml(%cnntemp) }
if (<link> isin %cnntemp) { inc %ttt 1 | set %cnnlink $+ %ttt $nohtml(%cnntemp) }
if (<pubDate> isin %cnntemp) { inc %ttttt 1 | set %cnndate $+ %ttttt $nohtml(%cnntemp) }
if (<description> isin %cnntemp) { inc %tttt 1 | set %cnndesc $+ %tttt $remove($nohtml(%cnntemp),$(<div class="feedflare">)) }
}
on *:sockclose:CNN: {
if (%cnnstory == All) {
var %o 3 | while (%o <= $var(%cnntitle*,0)) {
msg %cnnchan 4,15 [Title: $calc(%o -2) $+ ] $var(%cnntitle*,%o).value | inc %o
}
}
else {
if ($calc(%cnnstory +2) > $var(%cnntitle*,0)) { notice $nick There are only $calc($v2 -2) options. }
else {
msg %cnnchan 4,15 [Title:] $($+(%,cnntitle,$calc(%cnnstory +2)),2)
msg %cnnchan 4,15 [Published:] $($+(%,cnndate,$calc(%cnnstory +1)),2)
msg %cnnchan 4,15 [Description:] $($+(%,cnndesc,$calc(%cnnstory +2)),2)
msg %cnnchan 4,15 [Link:] $($+(%,cnnlink,$calc(%cnnstory +2)),2)
}
}
unset %cnn* %tt %ttt %tttt %ttttt
}
alias -l nohtml {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
return %x
}
little edit to make it notice the user
on *:text:!cnn *:#: {
if ($2 isnum && $2 >= 1) { set %cnnstory $round($2,0) }
if ($2 == sports) { set %cnnstory All | set %feed /rss/si_topstories.rss }
elseif ($2 == us) { set %cnnstory All | set %feed /rss/cnn_us.rss }
elseif ($2 == world) { set %cnnstory All | set %feed /rss/cnn_world.rss }
elseif ($2 == topstories) { set %cnnstory All | set %feed /rss/cnn_topstories.rss }
elseif ($2 == living) { set %cnnstory All | set %feed /rss/cnn_living.rss }
elseif ($2 == travel) { set %cnnstory All | set %feed /rss/cnn_travel.rss }
elseif ($2 == showbizz) { set %cnnstory All | set %feed /rss/cnn_showbiz.rss }
elseif ($2 == health) { set %cnnstory All | set %feed /rss/cnn_health.rss }
elseif ($2 == space) { set %cnnstory All | set %feed /rss/cnn_space.rss }
elseif ($2 == tech ) { set %cnnstory All | set %feed /rss/cnn_tech.rss }
elseif ($2 == politics) { set %cnnstory All | set %feed /rss/cnn_allpolitics.rss }
elseif ($2 == crime) { set %cnnstory All | set %feed /rss/cnn_crime.rss }
elseif ($2 == money) { set %cnnstory All | set %feed /rss/money_latest.rss }
elseif ($2 == recent) { set %cnnstory All | set %feed /rss/cnn_latest.rss }
elseif ($2 == help) { notice $nick triggers are sports, us, world, topstories, living, travel, showbizz, health, space, tech, politics, crime, money, recent
notice $nick type !cnn sports for sports news, !cnn us for USA news, etc. Then type !cnn 1 to 10 for more info
/halt }
set %cnnchan $chan
sockopen CNN rss.cnn.com 80
}
on *:sockopen:CNN: {
sockwrite -n $sockname GET %feed HTTP/1.1
sockwrite -n $sockname Host: rss.cnn.com
sockwrite -n $sockname Connection: close
sockwrite -n $sockname $crlf
}
on *:sockread:CNN: {
sockread %cnntemp
if (<title> isin %cnntemp) { inc %tt 1 | set %cnntitle $+ %tt $nohtml(%cnntemp) }
if (<link> isin %cnntemp) { inc %ttt 1 | set %cnnlink $+ %ttt $nohtml(%cnntemp) }
if (<pubDate> isin %cnntemp) { inc %ttttt 1 | set %cnndate $+ %ttttt $nohtml(%cnntemp) }
if (<description> isin %cnntemp) { inc %tttt 1 | set %cnndesc $+ %tttt $remove($nohtml(%cnntemp),$(<div class="feedflare">)) }
}
on *:sockclose:CNN: {
if (%cnnstory == All) {
var %o 3 | while (%o <= $var(%cnntitle*,0)) {
notice %cnnchan 4,15 [Title: $calc(%o -2) $+ ] $var(%cnntitle*,%o).value | inc %o
}
}
else {
if ($calc(%cnnstory +2) > $var(%cnntitle*,0)) { notice $nick There are only $calc($v2 -2) options. }
else {
notice %cnnchan 4,15 [Title:] $($+(%,cnntitle,$calc(%cnnstory +2)),2)
notice %cnnchan 4,15 [Published:] $($+(%,cnndate,$calc(%cnnstory +1)),2)
notice %cnnchan 4,15 [Description:] $($+(%,cnndesc,$calc(%cnnstory +2)),2)
notice %cnnchan 4,15 [Link:] $($+(%,cnnlink,$calc(%cnnstory +2)),2)
}
}
unset %cnn* %tt %ttt %tttt %ttttt
}
alias -l nohtml {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
return %x
}
If you change it to echo, how are you supposed to notice the result to people, as Jenny asked? Echoing is only for the client that runs the code to see.
The easiest way to do is just add the timers in each line output.
Another way is to write the result to a text file and then play it with the -n switch.
This script can further be improved without the use of sockclose event, as I've been told that's a lazy habit in socket scripting. And it saves unnecessary line reads.