tglogo.png
1 LIKES

Snippet


Current Temp/Weather

In Category Buzzen Posted by err0r On 01/07/16
Tags: buzzen err0r weather temp 

Simple !w command to get weather. ie: !w 38851, !w washington dc

If your default temp is supposed to be in Celsius then go to set %weatherw.m F and change the F to C
on *:start:{
  hmake weather 50 | if ($exists($qt($mircdirdata\weatherhash.txt))) { hload weather $qt($mircdirdata\weatherhash.txt) } 
}
alias baddy {
  var %n $numtok($ial($1).user,46)
  if (%n isnum 1-3) { return $gettok($ial($1).user,%n,46) }
  else { return $ial($1).user }
}
alias bstripstyle { return $strip($regsubex($1-, /\[(?:style\x20.*?|/style)\]/gi,$null)) }
on *:text:*!w*:#: {
  tokenize 32 $bstripstyle($1-)
  if ($1 == !w) && (!%ontext.flood.ck) {
    set -u3 %ontext.flood.ck on
    if (!$2-) && (!$hget(weather,$baddy($nick))) { msg $chan Sorry $nick there is no weather infomation saved for you. Please use !w <location/zip> | halt }
    if (!$2-) && ($hget(weather,$baddy($nick))) { set %weather.search $hget(weather,$baddy($nick)) }
    if ($2-) { 
      set %weather.search $replace($2-,$chr(32),+)
      hadd -m weather $baddy($nick) $replace($2-,$chr(32),+)
    }
    hsave -o weather $qt($mircdirdata\weatherhash.txt) | set %weather.chan $chan | getweatherw
  }
}


;==== WEATHER ================================================================
alias getweatherw { sockclose weatherw | unset %wcheck | set %weatherw.check 1 | sockopen -e weatherw www.wunderground.com 443 }
on *:sockopen:weatherw:{
  if ($sockerr) { sockclose $sockname | halt }
  sockwrite -n $sockname GET /cgi-bin/findweather/hdfForecast?query= $+ $replace(%weather.search,$chr(32),+,$chr(44),$chr(37) $+ 2C) HTTP/1.1
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:5.0)
  sockwrite -n $sockname HOST: www.wunderground.com
  sockwrite -n $sockname CONNECTION: Keep-alive
  sockwrite -n $sockname $str($crlf,2)
}
on *:sockread:weatherw: {
  ;;;; Set the below variable to C for Celsius or F for Fahrenheit You can visit wunderground.com to see which it uses for you.
  set %weatherw.m F
  if ($sockerr > 0) return
  var %weatherw
  sockread -fn %weatherw
  if ($regex(%weatherw,/<td><a href="(.*?)" title="(.*?)">(.*?)</a><\/td>/)) {
    set %weatherw.place $regml(3)
    set %wcheck 1
  }
  if (%wcheck == 1) && ($regex(%weatherw,/<span class=\"wx-data\"><span class=\"wx-value\">(.*?)<\/span><span class=\"wx-unit\">(.*?)<\/span>/)) {
    set %weatherw.temp $regml(1) $+ %weatherw.m
    set %weatherw.tempc $converttempw(%weatherw.temp)
    set %wcheck 2
  }
  if (%wcheck == 3) {
    set %weatherw.type %weatherw
    unset %wcheck
    sockclose $sockname
    sockwrite -n sock.server privmsg %weather.chan :[ %weatherw.place ] Currently %weatherw.temp / %weatherw.tempc %weatherw.type 
    unset weatherw.*
  }
  if (%wcheck == 2) && ($regex(%weatherw,/<td>/)) {
    set %wcheck 3
  }
  if ($regex(%weatherw,/<meta property=\"og:title\" content=\"(.*?)\" \/>/)) { 
    set %weatherw.ck $regml(1)
    set %weatherw.place $gettok(%weatherw.ck,1,124)
    set %weatherw.temp $replace($gettok(%weatherw.ck,2,124),°,%weatherw.m)
    set %weatherw.tempc $converttempw(%weatherw.temp)
    set %weatherw.type $gettok(%weatherw.ck,3,124)
    sockclose $sockname 
    msg %weather.chan $chr(91) %weatherw.place $chr(93) Currently %weatherw.temp / %weatherw.tempc %weatherw.type 
    unset %weatherw.*
  }
}  
alias converttempw {
  if ($right($1,1) == f) { return $round($calc((($remove($1,f) - 32) * 5) / 9),1) $+ C } 
  else { return $round($calc(($remove($1,c) * 1.8) + 32),1) $+ F }
}


Comments 4

err0r - Monday, 4 April, 2016
updated 04/03/16
Paige - Monday, 25 January, 2016
ooops, sorry errOr, wrong snippet! i meant to say the buzzen "show profile on join " is'nt working for me.
err0r - Sunday, 24 January, 2016
doesn't return any information? or wrong information?
Paige - Saturday, 23 January, 2016
It dont seem to work for mee, does anyone else have the same problem?

Please note that on our website we use cookies necessary for the functioning of our website, cookies that optimize the performance. To learn more about our cookies, how we use them and their benefits, please read our Cookie Policy.
I Understand