[color:green]; open the socket[/color]
alias abctest { sockopen abctest abcnews.go.com 80 }
[color:green] [/color]
on *:sockopen:abctest: {
[color:green]; HTTP protocol stuff[/color]
sockwrite -n $sockname GET /wire/world/index.html HTTP/1.0
sockwrite -n $sockname User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
sockwrite -n $sockname Connection: close
sockwrite -n $sockname host: abcnews.go.com
sockwrite -n $sockname Accept: */*
sockwrite -n $sockname $crlf
[color:green]; open a window and hide it, we don't need to see it[/color]
window -h @abc_tmp
}
[color:green] [/color]
on *:sockread:abctest: {
sockread %abc_temp
[color:green]; only proceed if the line has a valid value[/color]
if (*div*class="black9pt"* iswm %abc_temp) {
[color:green]; remove all HTML codes[/color]
%abc_temp = $removehtml(%abc_temp)
[color:green]; tokenize so I can use $1 $2 etc[/color]
tokenize 32 %abc_temp
[color:green]; read all but the last two tokens (which is the time it was posted)[/color]
var %abc_headline = $eval($+($,1-,$calc($0 - 2)),2)
[color:green]; write to the window[/color]
aline @abc_tmp %abc_headline
}
}
[color:green] [/color]
on *:SOCKCLOSE:abctest: {
[color:green]; compare window's first line to saved headline and save when necessary[/color]
if ($line(@abc_tmp,1) != %headline.last) set %headline.last $line(@abc_tmp,1)
[color:green]; cleaning up the mess[/color]
close -@ @abc_tmp
unset %abc_temp
}
[color:green] [/color]
[color:green]; a long time ago, in a galaxy far, far away, Hammer gave me a regex to remove HTML codes[/color]
alias removehtml {
var %return, %regex = $regsub($1-,/(^[^>]*>|<[^>]*>|<[^<]*$)/g,$null,%return)
return $remove(%return,$chr(9),&nbsp;)
}