Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- on *:TEXT:!temp*:#: {
- if ($istok($hget(hTemp,chans),#,4)) {
- if (%weather.flood) { return } | set -u2 %weather.flood 1
- if ($hget(temp)) hfree temp
- hadd -m temp chan #
- if ($2-) { hadd -m hTemp $ial($nick,1) $2- | hadd temp code $2- | temp.save }
- elseif ($hget(hTemp,$ial($nick,1))) { hadd temp code $v1 }
- else { msg # Please specify a location. | return }
- sockclose temp | sockopen temp www.wunderground.com 80
- } }
- on *:sockopen:temp: {
- sockwrite -n $sockname GET /cgi-bin/findweather/getForecast?query= $+ $replace($hget(temp,code),$chr(32),+) HTTP/1.1
- sockwrite -n $sockname HOST: www.wunderground.com $+ $str($crlf,3)
- }
- on *:sockread:temp: {
- sockread %r
- if (%r) {
- ;location
- if ($regex(%r, /<h1>(.*)</h1>/i)) {
- hadd temp loc $regml(1)
- }
- ;highs - 5 day
- elseif ($regex(%r, /color: #900;">(\d+))) {
- hinc temp iHi
- if ($hget(temp,iHi) == 2) {
- hadd temp hi $regml(1)
- } }
- ;lows - 5 day & F or C
- elseif ($regex(%r, /color: #009;">(\d+)° (.))) {
- hinc temp iLo
- if ($hget(temp,iLo) == 2) {
- hadd temp lo $regml(1)
- hadd temp scale $regml(2)
- } }
- ;current temp
- elseif (english="°F" isin %r) {
- if (!%wlnm) {
- noop $regex(%r, /value="([0-9]*\.?[0-9]*)")
- hadd temp current $regml(1)
- set -u2 %wlnm 1
- } }
- ;conditions
- elseif (class="condIcon" isin %r) {
- noop $regex(%r, /alt="(.+?)")
- if ($regml(1)) {
- hinc temp iCond
- hadd temp $+(cond, $hget(temp,iCond)) $v1
- if ($hget(temp,iCond) > 5) { displayTemp }
- } }
- elseif (</body> isin %r) {
- msg $hget(temp,chan) Weather location not found.
- }
- } }
- alias displayTemp {
- var %i $hget(temp,scale), %h $iif(%i == F, $FtoC($hget(temp,hi)) C, $CtoF($hget(temp,hi)) F), %l $iif(%i == F, $FtoC($hget(temp,lo)) C, $CtoF($hget(temp,lo)) F)
- msg $hget(temp,chan) In $hget(temp,loc) it is currently $hget(temp,current) F / $FtoC($hget(temp,current)) C - $hget(temp, cond3)
- msg $hget(temp,chan) Tomorrow the high is $hget(temp,hi) %i / %h and the low is $hget(temp,lo) %i / %l - $hget(temp, cond4)
- sockclose temp
- }
- menu channel {
- $style($iif($istok($hget(hTemp,chans),#,4),1,0)) Turn $iif($v1,off,on) Weather: {
- if ($istok($hget(hTemp,chans),#,4)) { hadd -m hTemp chans $remtok($hget(hTemp,chans),#,4) }
- else { hadd -m hTemp chans $addtok($hget(hTemp,chans),#,4) }
- temp.save
- } }
- alias FtoC { return $round($calc(($1 - 32) * .55),0) }
- alias CtoF { return $round($calc(($1 / .55) + 32),0) }
- alias temp.save { hsave hTemp temps.dat }
- on *:START: { hmake hTemp 5 | if ($exists(temps.dat)) hload hTemp temps.dat }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement