Weather Bot
Platform: mIRC
Published Dec 14, 2007
Updated Jul 27, 2012
This script will retrieve the weather for US zipcodes from the website
www.localweather.net.
Update: Added alias so you can trigger it yourself and message the channel with the response.
Update: Added axtra error checking to the alias ( weatherm ). Thanks to Tokensoup.
Update: Added extra stuff for UV and Preassure. ( help from some one who wishes to remain namelss )
Update 1/13/09: Added alteration to specified line as noted by A Hylian Human.
Big Update 1/13/09: Redid entire script. Added forecast option.
Update 1/16/09: Altered triggers and adjusted a few of the script lines.
Triggers listed below:
Updates above no longer valid for the newest version of script.
Will list either weather or forecast.
!w 12345
!w 12345
!weather 12345
!weather 12345
Will list forecast.
!f 12345
!forecast 12345
Update 27Jan10: Completely redid it using another site as the old one changed way to much to use.
Update 4Feb10: Updated Trigger regex thanks to Jethro_ Also updated the script to show Weather Warnings if there are any.
on $*:text:/^!w(eather)?|f(orecast)?/Si:#: {
if ($2 isnum) {
if ($istok(!w !weather,$1,32)) { set %usweatherWF W }
if ($istok(!f !forecast,$1,32)) { set %usweatherWF F }
set %usweatherzip $2 | set %usweatherchan $chan
sockopen usweather www.localweather.net 80
}
}
on *:sockopen:usweather: {
sockwrite -n $sockname GET $+(/weather/?pands=,%usweatherzip,&forecast=zandh) HTTP/1.1
sockwrite -n $sockname Host: www.localweather.net
sockwrite -n $sockname Connection: close
sockwrite -n $sockname Authorization: Basic
sockwrite -n $sockname $crlf
}
on *:sockread:usweather: {
sockread %whtemp
if (warnings.html isin %whtemp) { set %whtempwarn $remove($nohtml(%whtemp),$chr(9),Advisories) }
if (Location Not Found isin %whtemp) { set %whtempwrong Yes }
if (class="pname"> isin %whtemp) { set %whtemplocation $remove($nohtml(%whtemp),$chr(9)) }
; Weather
if (Lat: isin %whtemp) { set %whtemplat $remove($nohtml(%whtemp),$chr(9)) }
if (class="u-met"> isin %whtemp) { inc %t_t 1 | set %whtemperC $+ %t_t $remove($nohtml(%whtemp),$chr(9)) }
; Forecast
if (class="dt"> isin %whtemp) { inc %yy 1 | set %suweatherdate $+ %yy $remove($nohtml(%whtemp),$chr(9)) }
if (class="hi"> isin %whtemp) { inc %ii 1 | set %suweatherhi $+ %ii $remove($nohtml(%whtemp),$chr(9)) }
if (class="lo"> isin %whtemp) { inc %iii 1 | set %suweatherlo $+ %iii $remove($nohtml(%whtemp),$chr(9)) }
if (class="wx"> isin %whtemp) { inc %oo 1 | set %suweathercondition $+ %oo $remove($nohtml(%whtemp),$chr(9)) }
}
on *:sockclose:usweather: {
if (%whtempwrong = Yes) {
msg %usweatherchan That zip code is incorrect. Please try another one.
unset %t_t %y_y %whtemp* %usweather* %suweather* %oo %yy %ii
}
else {
msg %usweatherchan Location:12 %whtemplocation
if (%usweatherWF = W) {
var %whcurF $gettok(%whtemperC1,1,38) $+ $chr(176) F
var %whcurC $round($calc(($gettok(%whtemperC1,1,38) - 32) * 5/9),0) $+ $chr(176) C
msg %usweatherchan Latitude:03 $removecs($gettok(%whtemplat,4,58),N,E,S,W,Lon) Longitude:03 $removecs($gettok(%whtemplat,5,58),N,E,S,W,Lon)
msg %usweatherchan Currently:07 %whcurF /07 %whcurC and $gettok(%whtemperC1,2-,67) $&
Feels Like:7 $replace($gettok($remove(%whtemperC2,Feels Like:),1,70),°,$+($chr(176),$chr(32),F)) $&
/07 $round($calc($gettok($remove(%whtemperC2,Feels Like:),1,38) -32) *5/9),1) $+ $+($chr(176),$chr(32),C)
msg %usweatherchan Dew Point:13 $replace($gettok($gettok(%whtemperC3,2,58),1,70),°,$chr(176)) $+ $+($chr(32),F)) $&
/13 $round($calc($gettok($remove(%whtemperC3,Dew Point:),1,38) -32) *5/9),1) $+ $+($chr(176),$chr(32),C) $&
Pressure:10 $+($gettok($remove(%whtemperC5,Pressure:),1,110),n) /10 $gettok(%whtemperC5,2,110)
if (%whtempwarn) { msg %usweatherchan Weather Warning: $+ $+($chr(3),4,%whtempwarn) }
msg %usweatherchan Website: http://www.localweather.net/weather/?pands= $+ %usweatherzip $+ &forecast=zandh
}
if (%usweatherWF = F) {
msg %usweatherchan 7 $+ $usweather(%suweatherdate2) 4>>12 $iif(%suweatherhi1 = %suweatherlo2,$usweather2(%suweatherlo1),$usweather2($v1)) 4>>>3 %suweathercondition2
msg %usweatherchan 7 $+ $usweather(%suweatherdate3) 4>>12 $usweather2(%suweatherhi1) 4>>>3 %suweathercondition3
msg %usweatherchan 7 $+ $usweather(%suweatherdate4) 4>>12 $usweather2(%suweatherhi2) 4>>>3 %suweathercondition4
msg %usweatherchan 7 $+ $usweather(%suweatherdate5) 4>>12 $usweather2(%suweatherhi3) 4>>>3 %suweathercondition5
msg %usweatherchan 7 $+ $usweather(%suweatherdate6) 4>>12 $usweather2(%suweatherhi4) 4>>>3 %suweathercondition6
msg %usweatherchan 7 $+ $usweather(%suweatherdate7) 4>>12 $usweather2(%suweatherhi5) 4>>>3 %suweathercondition7
msg %usweatherchan 7 $+ $usweather(%suweatherdate8) 4>>12 $usweather2(%suweatherhi6) 4>>>3 %suweathercondition8
$iif($gettok(%suweatherdate9,2,32) isnum,msg %usweatherchan 7 $+ $usweather(%suweatherdate9) 4>>12 $usweather2(%suweatherhi7) 4>>>3 %suweathercondition9 )
$iif($gettok(%suweatherdate10,2,32) isnum,msg %usweatherchan 7 $+ $usweather(%suweatherdate10) 4>>12 $usweather2(%suweatherhi8) 4>>>3 %suweathercondition10 )
}
unset %t_t %y_y %whtemp* %usweather* %suweather* %oo %yy %ii %iii
}
}
alias usweather {
return $iif($istokcs(MON TUE WED THU FRI SAT SUN,$left($1,3),32),$replace($1,$left($1,3),$+($left($1,3),$chr(32))),$+($1,$chr(32)))
}
alias usweather2 {
return $replacecs($replace($1,:,$+(:,$chr(32)),°,$+($chr(176),$chr(32))),F,$+(F,$chr(32)))
}
alias -l nohtml {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
return %x
}