mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 204
K
keeker Offline OP
Fjord artisan
OP Offline
Fjord artisan
K
Joined: Dec 2002
Posts: 204
can someone tell me if there is a better easier way to script this? it is part of a weather script that i am makeing. everything works ok for the most part, but was just wondering if there was a quicker way of doing this:

Code:
 on *:sockclose:getwet:{
  if ( $line(@Weather_Parser,27) == Wind ) {
    set %city $remove($line(@Weather_Parser,8),$chr(9) $+ Forecast and )
    set %loc $replace($line(@Weather_Parser,11),Observed,$chr(32) $+ Observed) $line(@Weather_Parser,12)
    set %vis $line(@Weather_Parser,39) $+ : $line(@Weather_Parser,40) $+ $line(@Weather_Parser,41) $+ $line(@Weather_Parser,42)
    set %cond $line(@Weather_Parser,37) $+ :  $line(@Weather_Parser,38)
    set %wind $line(@Weather_Parser,27) $+ : $line(@Weather_Parser,28) $line(@Weather_Parser,29) $+ $line(@Weather_Parser,30) $+ $line(@Weather_Parser,31)
    set %temp $line(@Weather_Parser,13) $+ : $replace($line(@Weather_Parser,14),°,$chr(176)) $+ / $+ $replace($line(@Weather_Parser,16),°,$chr(176))
  } 
  elseif ( $line(@weather_parser,23) == Wind ) {
    set %city $remove($line(@Weather_Parser,8),$chr(9) $+ Forecast and )
    set %loc $replace($line(@Weather_Parser,11),Observed,$chr(32) $+ Observed) $line(@Weather_Parser,12)
    set %vis $line(@Weather_Parser,35) $+ : $line(@Weather_Parser,36) $+ $line(@Weather_Parser,37) $+ $line(@Weather_Parser,38)
    set %cond $line(@Weather_Parser,33) $+ : $line(@Weather_Parser,34)
    set %wind $line(@Weather_Parser,23) $+ : $line(@Weather_Parser,24) $line(@Weather_Parser,25) $+ $line(@Weather_Parser,26) $+ $line(@Weather_Parser,27)
    set %temp $line(@Weather_Parser,13) - $replace($line(@Weather_Parser,14),°,$chr(176)) $+ / $+ $replace($line(@Weather_Parser,16),°,$chr(176))

  } 
  window -c @Weather_Parser
  echo -a ============ %city ================================
  echo -a == %temp == %wind 
  echo -a == %cond == %vis 
  echo -a == %loc 
  echo -a ==========================================================
  unset %city %loc %vis %cond %wind %temp %query %getwet-temp
}
 


i know this code is really ugly


PS: Sorry bou the wide code, i dont know how to break it down to look nicer in the forums.


keek: Scots - intr.v. keeked, keek·ing, keeks
To peek; peep.
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Speed is not really an issue in this kind of script, so it's more about readability or shortness, so here's a try at that...

Code:
on *:sockclose:getwet:{
  var %o = 0
  if ($w(27) == Wind) var %o = 4
  var %city = $remove($w(8),$chr(9) $+ Forecast and )
  var %loc $replace($w(11),Observed,$chr(32) $+ Observed) $w(12)
  var %cv = $+($w(33,%o),: $w(34,%o) == $w(35,%o),: $w(36,%o),$w(37,%o),$w(38,%o))
  var %wind = $+($w(23,%o),: $w(24,%o) $w(25,%o),$w(26,%o),$w(27,%o)) 
  var %temp = $+($w(13,%o),: $replace($w(14,%o),°,°),/,$replace($w(16,%o),°,°))
  window -c @Weather_Parser
  echo -a ============ %city ================================
  echo -a == %temp == %wind 
  echo -a == %cv 
  echo -a == %loc 
  echo -a ==========================================================

}
alias -l w return $line(@Weather_Parser,$calc($1 + $2))


PS: I really think there should be a better way of storing information than in a custom window that you're about to clear to show other info...

Joined: Dec 2002
Posts: 204
K
keeker Offline OP
Fjord artisan
OP Offline
Fjord artisan
K
Joined: Dec 2002
Posts: 204
Thank you very much, with a little tweaking,not scripts fault but the weather site not sending the format all the time, it's working perfectly now.

as far as the window clearing/closing -- maybe hash tables?


keek: Scots - intr.v. keeked, keek·ing, keeks
To peek; peep.
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Hash tables are a good alternative, but maybe it's possible to do more work in the on sockread event so as to only write stuff you need to a %var/@window/hash table. It could be a simple counter with for each line or set of lines a new condition to check for. Ofcourse, it really depends on the structure of the webpage wether this is feasible or not.

For the hash tables now, just adding each line to a numbered item gives about the same functionality as a @window.

Check also the help file about /sockmark, there you can save up to 512 bytes of information for that socket connection. This data disappears after the sockclose event has finished, and might be useful for keeping the above mentioned line count or status.


Link Copied to Clipboard