on *:text:-weather *:#:{
set %weather.channel $chan
weather $2
}
alias weather {
if (!$1) {
msg %weather.channel No zip code specified.
unset %weather.channel
}
else {
if (!$regex($1,\d{5})) {
msg %weather.channel Incorrect zip code format.
unset %weather.channel
}
else {
if ($sock(weather)) sockclose weather
sockopen weather
www.w3.weather.com 80
sockmark weather $1
}
}
}
alias -l nohtml { var %tmp, %ignore = $regsub($1-,/(<[^>]+>)/g,$chr(32),%tmp) | return
%tmp }
alias convert {
if ($1 == $null) return $null
else {
if ($1 !isnum) return $null
else {
if ($prop == f2c) return $round($calc(($1 - 32) * 5 / 9),1)
if ($prop == c2f) return $round($calc(($1 * 9 / 5) + 32),1)
if ($prop == m2k) return $round($calc($1 * 1.61),1)
if ($prop == k2m) return $round($calc($1 * (1 / 1.61)),1)
}
}
}
on *:sockopen:weather:{
var %zip = $sock($sockname).mark
sockwrite -n $sockname GET /weather/local/ $+ %zip HTTP/1.1
sockwrite -n $sockname Host:
www.w3.weather.com sockwrite -n $sockname Connection: keep-alive
sockwrite -n $sockname
}
on *:sockread:weather:{
if ($sockerr > 0) return
:nextread
sockread %temp
if ($sockbr == 0) return
if (%temp == $null) var %temp = -
if (<A HREF="/" CLASS="breadCrumb">Home</a> > <B>Local Forecast for * (*)</b> iswm
%temp) {
var %temp = $nohtml($gettok(%temp,8-,32))
sockmark $sockname $sock($sockname).mark $+ $chr(255) $+ $gettok(%temp,1,40)
}
if (<TD VALIGN=MIDDLE ALIGN=CENTER CLASS=obsInfo2 WIDTH=50%><B
CLASS=obsTempTextA>*°F</b></td></tr> iswm %temp) {
var %temp = $nohtml(%temp)
sockmark $sockname $sock($sockname).mark $+ $chr(255) $+ $gettok(%temp,1,38)
}
if (<TR><TD VALIGN=TOP ALIGN=CENTER CLASS=obsInfo2><B CLASS=obsTextA>*</b></td> iswm
%temp) {
sockmark $sockname $sock($sockname).mark $+ $chr(255) $+ $nohtml(%temp)
}
if (<TD VALIGN=TOP ALIGN=CENTER CLASS=obsInfo2> <B CLASS=obsTextA>Feels
Like<BR>*°F</b></td></tr> iswm %temp) {
var %temp = $nohtml(%temp)
sockmark $sockname $sock($sockname).mark $+ $chr(255) $+ $gettok(%temp,1,38)
}
if (%temp == <TR><TD ALIGN=LEFT VALIGN=TOP CLASS=obsInfo1>Humidity:</td>) {
sockread %temp
sockmark $sockname $sock($sockname).mark $+ $chr(255) $+ $nohtml(%temp)
}
if (%temp == <TR><TD ALIGN=LEFT VALIGN=TOP CLASS=obsInfo1>Visibility:</td>) {
sockread %temp
sockmark $sockname $sock($sockname).mark $+ $chr(255) $+ $nohtml(%temp)
}
if (%temp == <TR><TD ALIGN=LEFT VALIGN=TOP CLASS=obsInfo1>Wind:</td>) {
sockread %temp
sockmark $sockname $sock($sockname).mark $+ $chr(255) $+
$gettok($nohtml(%temp),1,38)
}
if (*reported at</a>* iswm %temp) {
sockmark $sockname $sock($sockname).mark $+ $chr(255) $+
$nohtml($gettok(%temp,9-,44))
}
if (%temp == </html>) {
tokenize 255 $sock($sockname).mark
msg %weather.channel [^B] $+ $2 $+ [^B] ( $+ $1 $+ ): $3 $+ $chr(176) $+ F/ $+
$convert($3).f2c $+ $chr(176) $+ C ( $+ $5 $+ $chr(176) $+ F/ $+
$convert($gettok($5,3,32)).f2c $+ $chr(176) $+ C) - [^B] $+ Condition $+ [^B]: $4 - [^B] $+
Humiditiy $+ [^B]: $6 - [^B] $+ Visibility $+ [^B]: $7 ( $+ $convert($gettok($7,1,32)).m2k $+ km)
- [^B] $+ Wind $+ [^B]: $8 (Last Updated: $9 $+ )
unset %weather.channel
sockclose $sockname
return
}
goto nextread
}