All pastes #1288982 Raw Edit

Stuff

public text v1 · immutable
#1288982 ·published 2008-12-19 01:31 UTC
rendered paste body
;Usage /weatherm zipcode
alias weatherm {
  if ($1 isnum) && ($len($1) == 5) && ($active ischan) {
  weather $1 | set %we.chan $chan }
  elseif ($active !ischan) { echo -a Invalid window. (Use a channel window) }
  else {
    echo -a Incorrect zip code format.
  }
}

on *:TEXT:`weather*:#: {
  if ($2 isnum) && ($len($2) == 5) {
  weather $2 | set %we.chan $chan }
  else {
    msg $chan Incorrect zip code format.
  }
} 
alias weather {
  sockclose weather- $+ $replace($1-,$chr(32),+)
  sockopen weather- $+ $replace($1-,$chr(32),+) www.weather.com 80
}
alias -l nohtml {
  var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;)
  return %x
}


on *:SOCKOPEN:weather*:{
  sockwrite -n $sockname GET /weather/local/ $+ $gettok($sockname,2-,45) $+ ?lswe= $+ $gettok($sockname,2-,45) $+ &lwsa=WeatherLocalUndeclared&from=whatwhere HTTP/1.1
  sockwrite -n $sockname Host: www.weather.com
  sockwrite -n $sockname Connection: close
  sockwrite -n $sockname Authorization: Basic 
  sockwrite -n $sockname $crlf
}
on *:sockread:weather*: {
  sockread %temp
  if (">Updated isin %temp) {
    set %we.update $nohtml(%temp) | haltdef
  }
  if (*CLASS=obsTextA>*</B></TD>* iswm %temp) {
    set %we.cond %temp | set %we.condx $gettok($gettok(%we.cond,5,62),1,60) | haltdef
  }
  if (ALIGN="left"><H2 CLASS="moduleTitleBar"><B>Right Now for</B><BR> isin %temp) { 
    set %we.loc $remove($remove($gettok($nohtml(%temp),3-,32),for),Save Location) | haltdef
  }
  if (Feels Like isin %temp) { 
    set %we.temp $remove($nohtml(%temp),$chr(9)) | set %we.temperature $remove($replace($gettok(%we.temp,1,32),&deg;, $+ $chr(176)),Feels) | set %we.feelslike $chr(40) feels like $replace($gettok(%we.temp,3,32),&deg;, $+ $chr(176)) $chr(41) | haltdef
  }
  if (*CLASS="obsTextA">*%</td>* iswm %temp) {
    set %we.hum %temp | set %we.humidity $gettok($gettok(%we.hum,2,62),1,60) | haltdef 
  }
  if (*CLASS="obsTextA">*&nbsp;in. iswm %temp) {
    set %we.pr %temp | set %we.pressure $replace($gettok($gettok(%we.pr,2,62),1,60),&nbsp;,$chr(160)) | haltdef
  }
  if (*steady_pressure.gif">* iswm %temp) {
    set %we.pressurex %temp | set %we.pressures and steady | haltdef 
  }
  if (*up_pressure.gif">* iswm %temp) {
    set %we.pressurex %temp | set %we.pressurer and rising | haltdef 
  }
  if (*down_pressure.gif">* iswm %temp) {
    set %we.pressurex %temp | set %we.pressuref and falling | haltdef 
  }
  if (*CLASS="obsTextA">* Low</td>* iswm %temp) { 
    set %we.uv %temp | set %we.uvl $gettok($gettok(%we.uv,2,62),1,60) | haltdef
  }
  if (*CLASS="obsTextA">* Moderate</td>* iswm %temp) { 
    set %we.uv %temp | set %we.uvm $gettok($gettok(%we.uv,2,62),1,60) | haltdef
  }
  if (*CLASS="obsTextA">* High</td>* iswm %temp) { 
    set %we.uv %temp | set %we.uvh $gettok($gettok(%we.uv,2,62),1,60) | haltdef
  }
  if (*CLASS="obsTextA">*mph</td>* iswm %temp) {
    set %we.wind %temp | set %we.windex $gettok($gettok(%we.wind,2,62),1,60) | haltdef
  }
  if (*CLASS="obsTextA">calm</td>* iswm %temp) {
    set %we.wind %temp | set %we.windex %we.wind | haltdef
  }
  if (*CLASS="obsTextA">*mph</td>* iswm %temp) {
    set %we.wind %temp | set %we.windexg $gettok($gettok(%we.wind,3,62),1,60) | haltdef
  }
  if (*CLASS="obsTextA">*&deg;*</td>* iswm %temp) {
    set %we.dew %temp | set %we.dewpoint $replace($gettok($gettok(%we.dew,2,62),1,60),&deg;, $+ $chr(176)) | haltdef
  }
  if (sunrise: isin %temp) {
    set %we.sunrise $remove($nohtml(%temp),$chr(9),sunrise:)
  }
  if (sunset: isin %temp) {
    set %we.sunset $remove($nohtml(%temp),$chr(9),sunset:)
  }
  if (*CLASS="obsTextA">*miles</td>* iswm %temp) {
    set %we.vis %temp | set %we.visibility $gettok($gettok(%we.vis,2,62),1,60) | haltdef
  }
}
on *:SOCKCLOSE:weather*: {
  if (%we.loc == $null) { msg %we.chan Please choose another Zip Code. | halt }
  else {
    .timer 1 1 msg %we.chan 04Location: %we.loc 
    .timer 1 3 msg %we.chan 04Current Temp: %we.temperature / $round($calc(($remove(%we.temperature,$chr(176),$chr(70)) - 32 ) / 1.8),0) $+ $chr(176) $+ $chr(67) 04Feels Like: 02 $remove(%we.feelslike,$( feels like),$chr(41),$chr(40)) / $round($calc(($remove(%we.feelslike,$chr(40),$chr(41),$(feels like),$chr(176),$chr(70)) - 32 ) / 1.8),0) $+ $chr(176) $+ $chr(67)  
    .timer 1 5 msg %we.chan 03Current Conditions: %we.condx 03Pressure: %we.pressure %we.pressures %we.pressurer %we.pressuref 03Humidity: %we.humidity 03Visibility: %we.visibility 03UV Index: %we.uvl %we.uvm %we.uvh 03Wind: %we.windex %we.windexg 
    .timer 1 6 msg %we.chan 03Dew Point: %we.dewpoint ( $round($calc(($remove(%we.dewpoint,,$chr(176),$chr(70)) - 32) / 1.8),0) $+ $chr(176) $+ $chr(67) ) 03Sunrise: %we.sunrise 03Sunset: %we.sunset
    .timer 1 7 msg %we.chan 03Last Updated: %we.update 03Info From: www.weather.com | unset %we.* | unset %temp
  }
}