Advertisement
makimaki

Weather Underground

Aug 20th, 2010
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 2.71 KB | None | 0 0
  1. on *:TEXT:!temp*:#: {
  2.   if ($istok($hget(hTemp,chans),#,4)) {
  3.     if (%weather.flood) { return } | set -u2 %weather.flood 1
  4.     if ($hget(temp)) hfree temp
  5.     hadd -m temp chan #
  6.  
  7.     if ($2-) { hadd -m hTemp $ial($nick,1) $2- | hadd temp code $2- | temp.save }
  8.     elseif ($hget(hTemp,$ial($nick,1))) { hadd temp code $v1 }
  9.     else { msg # Please specify a location. | return }
  10.  
  11.     sockclose temp | sockopen temp www.wunderground.com 80
  12. } }
  13.  
  14. on *:sockopen:temp: {
  15.   sockwrite -n $sockname GET /cgi-bin/findweather/getForecast?query= $+ $replace($hget(temp,code),$chr(32),+) HTTP/1.1
  16.   sockwrite -n $sockname HOST: www.wunderground.com $+ $str($crlf,3)
  17. }
  18.  
  19. on *:sockread:temp: {
  20.   sockread %r
  21.   if (%r) {
  22.  
  23.     ;location
  24.     if ($regex(%r, /<h1>(.*)</h1>/i)) {
  25.       hadd temp loc $regml(1)
  26.     }
  27.  
  28.     ;highs - 5 day
  29.     elseif ($regex(%r, /color: #900;">(\d+))) {
  30.       hinc temp iHi
  31.       if ($hget(temp,iHi) == 2) {
  32.         hadd temp hi $regml(1)
  33.     } }
  34.  
  35.     ;lows - 5 day & F or C
  36.     elseif ($regex(%r, /color: #009;">(\d+)&deg; (.))) {
  37.       hinc temp iLo
  38.       if ($hget(temp,iLo) == 2) {
  39.         hadd temp lo $regml(1)
  40.         hadd temp scale $regml(2)
  41.     } }
  42.  
  43.     ;current temp
  44.     elseif (english="&deg;F" isin %r) {
  45.       if (!%wlnm) {
  46.         noop $regex(%r, /value="([0-9]*\.?[0-9]*)")
  47.         hadd temp current $regml(1)
  48.         set -u2 %wlnm 1
  49.     } }
  50.  
  51.     ;conditions
  52.     elseif (class="condIcon" isin %r) {
  53.       noop $regex(%r, /alt="(.+?)")
  54.       if ($regml(1)) {
  55.         hinc temp iCond
  56.         hadd temp $+(cond, $hget(temp,iCond)) $v1
  57.         if ($hget(temp,iCond) > 5) { displayTemp }
  58.     } }
  59.  
  60.     elseif (</body> isin %r) {
  61.       msg $hget(temp,chan) Weather location not found.
  62.     }
  63. } }
  64.  
  65. alias displayTemp {
  66.   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)
  67.   msg $hget(temp,chan) In $hget(temp,loc) it is currently $hget(temp,current) F / $FtoC($hget(temp,current)) C - $hget(temp, cond3)
  68.   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)
  69.   sockclose temp
  70. }
  71.  
  72.  
  73. menu channel {
  74.   $style($iif($istok($hget(hTemp,chans),#,4),1,0)) Turn $iif($v1,off,on) Weather: {
  75.     if ($istok($hget(hTemp,chans),#,4)) { hadd -m hTemp chans $remtok($hget(hTemp,chans),#,4) }
  76.     else { hadd -m hTemp chans $addtok($hget(hTemp,chans),#,4) }
  77.     temp.save
  78. } }
  79.  
  80. alias FtoC { return $round($calc(($1 - 32) * .55),0) }
  81. alias CtoF { return $round($calc(($1 / .55) + 32),0) }
  82. alias temp.save { hsave hTemp temps.dat }
  83. on *:START: { hmake hTemp 5 | if ($exists(temps.dat)) hload hTemp temps.dat }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement