UK Weather Bot

By Scakk on Jan 16, 2009

This script will return the weather in the UK and Ireland using postcodes.

Image

Usage: !ukweather pe3 6hr

or

Usage: !ukweather ng21 0st

Updated 28Jan09: Updated to allow the 7 or 6 digit postcodes. No longer able to put it together. Has to be spaced as shown in usages above.

on *:text:!ukweather*:#: {
    if ($len($2) == 3 && $len($3) == 3) { 
      set %ukw2 $2 | set %ukw3 $3 | set %ukwchan $chan
      sockopen ukweather www.accuweather.com 80
    }
    if ($len($2) == 4 && $len($3) == 3) {
      set %ukw2 $2 | set %ukw3 $3 | set %ukwchan $chan
      sockopen ukweather www.accuweather.com 80
    }
}

on *:sockopen:ukweather: { 
  sockwrite -n $sockname GET /ukie/index-forecast.asp?postalcode= $+ $+(%ukw2,$chr(43),%ukw3) HTTP/1.1 
  sockwrite -n $sockname Host: www.accuweather.com
  sockwrite -n $sockname Connection: close 
  sockwrite -n $sockname $crlf
}
on *:sockread:ukweather: {
  if ($sockerr > 0) return 
  sockread %ukwtemp 
  if ($sockbr == 0) return
  if (<div id="fcst_title"> isin %ukwtemp) { set %ukwloc $nohtml(%ukwtemp) }
  if (_current_temps"> isin %ukwtemp) { set %ukwcurrent $replace($nohtml(%ukwtemp),$(&deg;),$chr(176)) }
  if (_current_rfval"> isin %ukwtemp) { set %ukwreal $replace($nohtml(%ukwtemp),$(&deg;),$chr(176)) }
  if (_curr_icon" isin %ukwtemp) { set %ukwcond1 $remove($gettok(%ukwtemp,-1,61),$chr(34),$(/>)) } 
  if (_current_wxtext"> isin %ukwtemp) { set %ukwcond2 $nohtml(%ukwtemp) }
  if (Humidity: isin %ukwtemp) { set %ukwhumidity $remove($nohtml(%ukwtemp),Humidity:,$chr(9)) }
  if (Dew Point: isin %ukwtemp) { set %ukwdewpoint $remove($replace($nohtml(%ukwtemp),$(&deg;),$chr(176)),Dew Point:,$chr(9)) }
  if (Pressure: isin %ukwtemp) { set %ukwpressure $remove($nohtml(%ukwtemp),Pressure:,$chr(9)) }
  if (Visibility: isin %ukwtemp) { inc %t 1 | set %ukwvisibility $+ %t $nohtml(%ukwtemp) }
  if (quicklook_curr_head" isin %ukwtemp) { set %ukwcurtime $nohtml(%ukwtemp) }

}
on *:sockclose:ukweather: {
  if (!%ukwloc) { msg %ukwchan Please choose another postcode as that ones does not exists. }
  if (%ukwloc) { 
    msg %ukwchan Location: $remove(%ukwloc ,$chr(9))
    msg %ukwchan Current Condition: %ukwcond1 and $remove(%ukwcond2,$chr(9))
    msg %ukwchan Currently: $remove(%ukwcurrent,$chr(9)) Feels Like: $remove(%ukwreal,$chr(9))
    msg %ukwchan Humidity: %ukwhumidity Dew Point: $remove(%ukwdewpoint,$chr(32))
    msg %ukwchan Pressure: %ukwpressure Visibility: $remove(%ukwvisibility1,Visibility:,$chr(32),$chr(9))
    msg %ukwchan $remove(%ukwcurtime,$chr(9)) in $remove(%ukwloc,$chr(9))
    msg %ukwchan http://www.accuweather.com/ukie/index-forecast.asp?postalcode= $+ $+(%ukw2,$chr(43),%ukw3)
  }
  unset %ukw* %t*
}
alias -l nohtml {
  var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;)
  return %x
}

Comments

Sign in to comment.
Iamred   -  Feb 14, 2012

[14:08] Iamred !ukweather cm2 6uf
[14:08] IamredBOT Please choose another postcode as that ones does not exists.

wut.

 Respond  
Jethro   -  Dec 03, 2010

Yeah it's an easy tweak. All you gotta do is:

on *:text:!ukweather*:#: { ukweather $2- }
alias ukweather {
  ;the rest of code goes in here

Now, you can have this script trigger both ways via:
/ukweather for self-trigger and !ukweather for other people.

It still needs an edit for the $1 and $2 and $3

 Respond  
napa182   -  Dec 03, 2010

@Kev_UK well it is called UK Weather Bot meaning it's for a bot but you can always make an alias to trigger it for ur self.

 Respond  
Kev_UK   -  Dec 03, 2010

Would be nice if running mirc and the addon you can actually check the weather by using the command, as it doesn't seem to work unless you boot another mirc up or as a friend to check weather for you.

 Respond  
SnoooP   -  Jan 10, 2010

Awesome Scakk, I really like this mate good job!

 Respond  
undertaker28   -  Jan 27, 2009

for some reason dont pick up all postcoed otherwise brill

 Respond  
Scakk   -  Jan 17, 2009

Once I can figure out how to get the weather from all parts of the world I will build the World Weather Bot :D :D

 Respond  
BabyJesus   -  Jan 17, 2009

;o another well done script scakk, around the world next man, they should have a global weather shits though man, make this alot ezer.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.