Canada Weather Bot

By Scakk on Jan 16, 2009

This one will get the weather for locations in Canada using postcodes.

Usage: !caweather M3H 6A2

or

Usage: !caweather M3H6A2

Image

on *:text:!caweather*:#: {
  if ($len($2) == 6) { 
    set %caw2 $left($2,3) | set %caw3 $right($2,3) | set %cawchan $chan
    sockopen caweather www.accuweather.com 80
  }
  if ($len($2) == 3 && $len($3) == 3) { 
    set %caw2 $2 | set %caw3 $3 | set %cawchan $chan
    sockopen caweather www.accuweather.com 80
  }
}
on *:sockopen:caweather: { 
  sockwrite -n $sockname GET /canada-weather-forecast.asp?partner=accuweather&traveler=0&postalcode= $+ $+(%caw2,$chr(43),%caw3) HTTP/1.1 
  sockwrite -n $sockname Host: www.accuweather.com
  sockwrite -n $sockname Connection: close 
  sockwrite -n $sockname $crlf
}
on *:sockread:caweather: {
  if ($sockerr > 0) return 
  sockread %cawtemp 
  if ($sockbr == 0) return
  if (class="cityTitle"> isin %cawtemp) { set %cawloc $nohtml(%cawtemp) }
  if (_current_temps"> isin %cawtemp) { set %cawcurrent $replace($nohtml(%cawtemp),$(°),$chr(176)) }
  if (_current_rfval"> isin %cawtemp) { set %cawreal $replace($nohtml(%cawtemp),$(°),$chr(176)) }
  if (_curr_icon" isin %cawtemp) { set %cawcond1 $remove($gettok(%cawtemp,-1,61),$chr(34),$(/>)) } 
  if (_current_wxtext"> isin %cawtemp) { set %cawcond2 $nohtml(%cawtemp) }
  if (Humidity: isin %cawtemp) { set %cawhumidity $remove($nohtml(%cawtemp),Humidity:,$chr(9)) }
  if (Dew Point: isin %cawtemp) { set %cawdewpoint $remove($replace($nohtml(%cawtemp),$(°),$chr(176)),Dew Point:,$chr(9)) }
  if (Pressure: isin %cawtemp) { set %cawpressure $remove($nohtml(%cawtemp),Pressure:,$chr(9)) }
  if (Visibility: isin %cawtemp) { inc %t 1 | set %cawvisibility $+ %t $nohtml(%cawtemp) }
  if (quicklook_curr_head" isin %cawtemp) { set %cawcurtime $nohtml(%cawtemp) }
}
on *:sockclose:caweather: {
  if (!%cawloc) { msg %cawchan Please choose another postcode as that ones does not exists. }
  if (%cawloc) { 
    msg %cawchan Location: $remove(%cawloc ,$chr(9))
    msg %cawchan Current Condition: %cawcond1 and $remove(%cawcond2,$chr(9))
    msg %cawchan Currently: $remove(%cawcurrent,$chr(9)) Feels Like: $remove(%cawreal,$chr(9))
    msg %cawchan Humidity: %cawhumidity Dew Point: $remove(%cawdewpoint,$chr(32))
    msg %cawchan Pressure: %cawpressure Visibility: $remove(%cawvisibility1,Visibility:,$chr(32),$chr(9))
    msg %cawchan $remove(%cawcurtime,$chr(9)) in $remove(%cawloc,$chr(9))
    msg %cawchan http://www.accuweather.com/canada-weather-forecast.asp?partner=accuweather&traveler=0&postalcode= $+ $+(%caw2,$chr(43),%caw3)
  }
  unset %caw* %t*
}
alias -l nohtml {
  var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;)
  return %x
}

Comments

Sign in to comment.
pUtRaDeWa   -  Jan 29, 2009

bro please help me
tell the snippet for indonesia / asian weather bot

i try to make it self but its not working

the url of forecas in indonesia is
http://www.bmg.go.id/cuaca-indo1.bmg?Jenis=URL&IDS=3356283939755564582

please help me bro

 Respond  
Calliope   -  Jan 19, 2009

as a CANADIAN I wanna say thanks this is VERY useful for me. Not too floody either which is appreciated on the server I ghost these days. As always good work ;D /me gives a cookie to Scakk ;P (that must have been a warm day in North York lol )

 Respond  
Aucun50   -  Jan 18, 2009

/me give 10/10 for great work and use full.

 Respond  
BabyJesus   -  Jan 17, 2009

whoo i give it a 15 in canadian!. Well done scakk ol bboi.

 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.