tglogo.png
0 LIKES

Snippet


Weather OnText 2.1

In Category Buzzen Posted by err0r On 09/06/10
Tags: weather buzzen err0r 

This is an update to my weather script that I've had for awhile. I just noticed it in one of my scripts so I thought I would pass it on. It just includes the time as well as the weather. It will keep up with the users previous request so future requests can be made using .w only. As always feel free to edit this and use however you wish.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;     Weather v2.1    ;;;
;;;   Created by err0r   ;;;
;;; http://www.tg007.net ;;;
;;;   use .w <location>  ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
menu channel {
  $iif($istok(%Weatherstore.Log,$chan,44),$style(1)) Weather $chan : $iif($istok(%Weatherstore.Log,$chan,44),set %Weatherstore.Log $remtok(%Weatherstore.Log,$chan,1,44),set %Weatherstore.Log $addtok(%Weatherstore.Log,$chan,44))
  Weather Settings
  .Clear Log : hfree weather | $iif($exists(weatherhash.txt),/remove -d weatherhash.txt) | hmake weather 50
  .View Log : weatherlog
  -
}
on *:start: { hmake weather 50 |  if ($exists(weatherhash.txt)) { hload weather weatherhash.txt } }
on *:exit: { hfree weather }
on *:text:*:#: {
  var %text $regsubex($1-, /\[(?:style\x20.*?|/style)\]/gi,$null)
  tokenize 32 %text
  if ($1 == .w) && (!%flood.ck) && ($istok(%Weatherstore.Log,$chan,44)) {
    set -u3 %flood.ck on
    if (!$2) && (!$hget(weather,$address($nick,1))) { raw notice $chan $nick Sorry $nick there is no weather infomation saved for you. Please use .w <location/zip> | halt }
    if (!$2) && ($hget(weather,$address($nick,1))) { unset %weather.* | set %weather.search $hget(weather,$address($nick,1)) }
    if ($2) { unset %weather.* | set %weather.search $2- | hadd -m weather $address($nick,1) $2- }
    hsave -o weather weatherhash.txt | set %weather.chan $chan | getweather
  }
}
alias getweather { unset %weather.searchtype | set %weather.searchtype weather+ | sockclose weather | set %weather.check 1 | sockopen weather search.yahoo.com 80 }
alias converttemp {
  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 }
}
on *:sockopen:weather:{
  write -c weather.txt
  if ($sockerr) { sockclose $sockname | halt }
  sockwrite -n $sockname GET /search?p= $+ %weather.searchtype $+ $replace(%weather.search,$chr(32),+,$chr(44),$chr(37) $+ 2C) HTTP/1.1
  sockwrite -n $sockname HOST: search.yahoo.com
  sockwrite -n $sockname CONNECTION: Keep-alive
  sockwrite -n $sockname $str($crlf,2)
}
on *:sockread:weather: {
  if ($sockerr > 0) return
  var %weather
  if (!%weather.time) { sockread -f %weather }
  else { sockread -f %weather }
  if (!%weather.time) {
    if ($regex(%weather,/Extended <b>weather <\/b>forecast for (.*?)<\/a>/)) { set %weather.info $chr(91) $remove($regml(1),<b>,</b>) $chr(93) <timehere> | inc %weather.check }
    if ($regex(%weather,/<\/div><p>Currently: (.*?)<\/p><p>(.*?)<\/p><p>/)) { set %weather.info %weather.info $remove($regml(1),°) / $converttemp($remove($regml(1),°)) - $regml(2) | inc %weather.check }
    if ($regex(%weather,/<p>Tomorrow<\/p><p>(.*?)<\/p><p>(.*?) \| (.*?)<\/p>/)) { set %weather.info %weather.info -- Tomorrow: $regml(1) - High: $remove($regml(2),°) / $converttemp($remove($regml(2),°)) - Low: $remove($regml(3),°) / $converttemp($remove($regml(3),°)) | inc %weather.check }
  }
  if (%weather.time) {
    if ($regex(%weather,/<b>Time<\/b> is <b>(.*?)<\/b>/)) { set %weather.info $replace(%weather.info,<timehere>,Currently: $regml(1) <timehere>  ) | inc %weather.check }
    if ($regex(%weather,/ \((.*?)\) on (.*?) -/)) { set %weather.info  $replace(%weather.info,<timehere>,$regml(1) $regml(2) - ) | inc %weather.check }
  }
  if (%weather == 0) || (%weather.check) {
    if (%weather.time) && (%weather.check == 3)  {
      sockclose $sockname
      .msg %weather.chan $iif(%weather.info,$v1,Search for $replace(%weather.search,$chr(37) $+ 20,$chr(32)) was not successful. Please refine your search.)
      unset %weather.*
    }
    if (!%weather.time) && (%weather.check == 4) { set %weather.searchtype time+ | set %weather.time on | sockclose weather | set %weather.check 1 | sockopen weather search.yahoo.com 80 }
  }
}
on *:sockclose:weather: {
  if (%weather.time) || (!%weather.info) {
    .msg %weather.chan $iif(%weather.info,$remove($v1,<timehere>),Search for $replace(%weather.search,$chr(37) $+ 20,$chr(32)) was not successful. Please refine your search.)
    unset %weather.*
  }
}
alias weatherlog {
  if (!$window(@weatherlog)) { /window -blk -t2,21 +benstx @weatherlog verdana 11 }
  clear @weatherlog | aline @weatherlog $chr(9) Address $chr(9) Weather Search | aline @weatherlog $chr(160)
  %hh = 1 | %hhn = $hget(weather, 0).item
  while (%hh <= %hhn) { aline -p @weatherlog $+(%hh,.) $chr(9) $hget(weather,%hh).item $chr(9) $hget(weather,%hh).data | inc %hh  }
}


Comments 0


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