mIRC Home    About    Download    Register    News    Help

Print Thread
Own made weather script no errors however... #188408 22/10/07 05:26 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
First off here's the code

Recongnizes both Canadian and U.S. Codes


Code:
dialog weather {
  title "Weather Get - 15 Day View"
  size -1 -1 291 120
  option dbu
  list 1, 2 1 240 152, size
  button "Get Weather", 2, 248 29 37 12, flat
  text "Zip/Post Code", 4, 248 6 36 8
  edit "XXX XXX", 6, 253 16 27 10
  box "", 7, 243 -1 44 45
}


on *:dialog:weather:sclick:2:jobs

alias jobs { 
  did -r weather 1
  if ($len($did(weather,6)) == 7) { %w.codes = $gettok($v1,1,32) $+(20,$gettok($v1,2,32)) | %w.codes = $replace(%w.codes,$chr(32),$chr(37)) | %wea = 1 | sockopen jobs www.accuweather.com 80 }
;I need a better check here ^ for postal code.
  elseif ($len($did(weather,6)) == 6) { echo -a Invalid Postal code XXX XXX is correct. / or You added a digit to many to zipcode }
  else { %w.codes = $did(weather,6) | unset %wea | sockopen jobs www.accuweather.com 80 }
}

on 1:sockopen:jobs:{
  if (%wea) { 
    .sockwrite -n jobs GET $+(/canada-forecast.asp?partner=accuweather&traveler=0&postalcode=,%w.codes,&metric=1&set=99) HTTP/1.1
    .sockwrite -n jobs HOST: www.accuweather.com
    .sockwrite -n jobs $crlf
  }
  else { 
    .sockwrite -n jobs GET $+(/forecast-15day.asp?partner=accuweather&traveler=0&zipChg=1&zipcode=,%w.codes,&metric=0) HTTP/1.1
    .sockwrite -n jobs HOST: www.accuweather.com
    .sockwrite -n jobs $crlf
  }
}

on 1:sockread:jobs:{
  if ($sockerr > 0) return 
  var %x | sockread %x
  if ($sockbr == 0) return 
  if (%x == $null) { return }
  if ($regex(%x,/(Locations|Days|Weekends|Radar|English|Developers|Details|Temperature)/b) == 1) { return } 
  if ($regex(%x,/(fday|metric)/b) == 1) { %weather = $+([,$nhtml(%x),]) - }
  if ($regex(%x,/(forecastHeaderLeft|fcst|</div>|metric|&amp)/g) == 2) {
    if (smtextbox isin %x) { %weather = %weather $+([,$nhtml(%x),]) - }
    if (RealFeel isin %x) { %weather = %weather .:Tempature:. $+([,$nhtml(%x)) }
    if (Temp isin %x) { 
      if ($len(%weather) > 20) {  did -a weather 1 %weather $+($nhtml(%x),]) }
      else { return }
    }
  }
}

alias -l nhtml { return $remove($regsubex($1-,/(&nbsp;|&deg;|^[^<]*>|<[^>]*>|<[^>]*$)/g,),$chr(9)) }


I tried to use isalnum like this $did(weather,6) isalnum so for the postal code it makes sure its an alpha numeric string and well the script halts or something.


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Own made weather script no errors however... [Re: Lpfix5] #188411 22/10/07 08:23 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Well, isalnum won't work with a space, I don't think. Personally, I'd just let all codes go through and then check the reply from the site for any errors and then display an error if there isn't a match. You'll want to do that anyhow because even if someone were to use a 5 digit number for a zip code, it wouldn't necessarily be a valid zip code.

Feel free to check out my weather script (it's 2 parts right now - server and user because I never did make a combined version). It might give you some ideas.


Invision Support
#Invision on irc.irchighway.net
Re: Own made weather script no errors however... [Re: Riamus2] #188424 23/10/07 12:37 AM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Yeah its cool I did $remove($did(weather,6),($chr(32)) isalnum works fine


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }