Jump to content

Weather Find Snippet


err0r

Recommended Posts

Here is a simple google weather finder i threw together.. saves user search so when they do .w <location/zip> it will save it so next time they can just use .w and it will return their last search. Channel menu contains per channel activation.

 

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))) { set %weather.search $hget(weather,$address($nick,1)) }
    if ($2) { set %weather.search $replace($2-,$chr(32),$chr(37) $+ 20) | hadd -m weather $address($nick,1) $replace($2-,$chr(32),$chr(37) $+ 20)  }
    hsave -o weather weatherhash.txt | set %weather.chan $chan | getweather
  }
}
alias getweather { sockclose weather | set %weather.check 1 | sockopen weather google.com 80 }
on *:sockopen:weather:{
  if ($sockerr) { sockclose $sockname | halt }
  sockwrite -n $sockname GET /search?hl=en&q=Weather%20in%20 $+ %weather.search HTTP/1.1
  sockwrite -n $sockname HOST: www.google.com
  sockwrite -n $sockname CONNECTION: Keep-alive
  sockwrite -n $sockname $str($crlf,2)
}
on *:sockread:weather: {
  if ($sockerr > 0) return
  var %weather
  sockread %weather
  if (%weather == 0) || (%weather.check > 2) {
    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.*

  }
  else {
    if (%weather.check == 1) var %weatherr = /<title>(.*)<\/title>/ig
    if (%weather.check == 2) var %weatherr = /<b>Weather<\/b> for <b>(.*)<\/b><\/div><div style="float:left"> - <a href=(.*)>Add to iGoogle<\/a><\/div><tr><td><div style="padding:5px;float:left"><div style="font-size:140%"><b>(.*)</b></div><div>(.*)</div></div>/ig
    if ($regex(weather, %weather, %weatherr) > 0) {
      if (%weather.check == 1)  set %weather.topic $regml(weather,1)
      if (%weather.check == 2)  set %weather.info $chr(91) $regml(weather,1) $chr(93) $replace($regml(weather,3),$chr(176),$chr(32)) / $round($calc((($remove($regml(weather,3),$chr(176),f) - 32) * 5) / 9),1) C - $remove($replace($regml(weather,4),<br>, $chr(32) $+ - $+ $chr(32) ),<b>,</b>,Current:)
      inc %weather.check
    }
  }
}
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 $+(14,%hh,.) $chr(9) 1 $hget(weather,%hh).item $chr(9) 1 $hget(weather,%hh).data | aline @weatherlog $chr(160) | inc %hh  }
}

 

Note when you edit a post that uses inside the code tags IPB may remove them.

 

Here is a txt file of the above code to avoid any mistakes.

 

weather.txt

Link to comment
Share on other sites

if some ppl from other countries outside of the u.s. could test this for me and give me some feedback on any problems they have i would appreciate it.. I'm sure it will have some issues.

Link to comment
Share on other sites

if some ppl from other countries outside of the u.s. could test this for me and give me some feedback on any problems they have i would appreciate it.. I'm sure it will have some issues.

 

:oops: I live in the uk ... matter of fact im in north yorkshire and live close to york city ... now im in a test room in spcn and I have typed !weather (nothing) iv typed !weather north yorkshire (nothing) :lolwave: iv gone through all the yorkshire ridings and (nothing) am I doing something wrong. err0r that is the only feed back I can give you at the moment fella.

Link to comment
Share on other sites

:oops: I live in the uk ... matter of fact im in north yorkshire and live close to york city ... now im in a test room in spcn and I have typed !weather (nothing) iv typed !weather north yorkshire (nothing) :lolwave: iv gone through all the yorkshire ridings and (nothing) am I doing something wrong. err0r that is the only feed back I can give you at the moment fella.

 

 

Johnson the trigger is .w

 

so do .w york

 

and make sure its turned on for that room

 

err0r treid it last night as u will have seen and it works fine :)

Link to comment
Share on other sites

Johnson the trigger is .w

 

so do .w york

 

and make sure its turned on for that room

 

err0r treid it last night as u will have seen and it works fine :)

 

:lmaojump: Haggis your to late fella :lolwave: get up earlier :P been testing it in spcn room :P but nais tuke for looking out for me :D

Link to comment
Share on other sites

:lmaojump: Just some thing or nothing err0r I was messing in spcn and my test room with a few old msn codes and I love that "Weather Code" so I started playing just typed a few places that iv been to in the pass few weeks for the weather and if you take a look at the screen shot you will see what I mean :D im not bother as soon as I put a UK at the end of it ..... it showed me it the right way .... as I said it is something and nothing but just wanted to show you.

 

post-27425-1251310087_thumb.jpg

Link to comment
Share on other sites

seems that problem was due to the google ads on the right hand side. I didn't take those into consideration. I have updated the weather snippet to fix that problem

 

http://www.tg007.net/dlss/index.php?action=file&id=1272

 

Version should say at the top v1.2 or it is not the latest version.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...