| View previous topic :: View next topic |
| Author |
Message |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Apr 25, 2006 5:00 pm Post subject: new version of convert.tcl |
|
|
Another completely re-written script. Trimmed all the fat, made it special-char safe, etc. All of the conversion binds now go through one main proc, this reduces the amount of redundant code, making the script lean and mean. An added bonus is the capacity to use the .calc function for almost anything you can use [expr] for, but in a safe manner (I say almost, because it will not handle variables, command substitutions in [], or other unsafe procedures =)
Script can be found here:
http://members.dandy.net/~fbn/convert.2.tcl.txt
For those who may not know, convert.tcl does conversions to/from metric/imperial units, and also has a mathematical/arithmetical calculator. |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Wed Apr 26, 2006 3:47 am Post subject: |
|
|
calc won't work with expressions containing adjacent whitespaces _________________ connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Wed Apr 26, 2006 4:46 am Post subject: |
|
|
| You mean like '1 + 1' ? Not sure I follow your meaning. |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Wed Apr 26, 2006 5:03 am Post subject: |
|
|
my calc bind looks like that and I am pretty confident about the safety:
| Code: | ...
set text [string map {[ ( ] ) $ " dollar "} $text]
...
catch {set ergebnis [expr $text]} fehler
... | At least I failed with all my imaginations to force a second substitition. _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Wed Apr 26, 2006 5:17 am Post subject: |
|
|
| rosc2112 wrote: | | You mean like '1 + 1' ? Not sure I follow your meaning. |
you might want to take a look at my FAQ post about splitting _________________ connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Wed Apr 26, 2006 5:28 pm Post subject: |
|
|
I don't see that as a problem, it just makes the script return an error msg.
| Quote: |
you might want to take a look at my FAQ post about splitting |
It does use split on the user input.
I made one small update to the script as well, to use [split] on the calc $reply, so that replies are properly formated (otherwise it drops chars when [join $rep] is sent to the user.)
Found a few typos too, fixed  |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Thu Apr 27, 2006 7:45 pm Post subject: |
|
|
Neat. Thanks  |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Sat Jun 10, 2006 2:58 pm Post subject: v205b |
|
|
Some minor updates to the convert script. v205b. Same url as above.
21/5/06 - Added inch/centimeter conversion..
27/5/06 - A better string2list was posted in egghelp.org and is now incorporated here. |
|
| Back to top |
|
 |
incith Master

Joined: 23 Apr 2005 Posts: 275 Location: Canada
|
Posted: Mon Jun 12, 2006 4:30 pm Post subject: |
|
|
I'm not sure how this post will be taken, but by all means I am not trying to prevent people from using your script.
I just thought I would point out, incith:google script, and Google itself, does conversions for just about anything. I can even calculate download times with something like 5 MB / 50 KB/s = (5 MB) / (50 (KB / s)) = 102.4 seconds, or you can do 5 MB / 50 KB/s in minutes, and your result would be in minutes.
Perhaps this post is more directed at those that may already use :google script.
Good job though, a local conversions script will always be faster than one doing net lookups.
Again, sorry if I've intruded this thread, I'm not looking for props on my scripts or anything. *paranoid*  _________________ ; Answer a few unanswered posts! |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Jun 13, 2006 1:27 am Post subject: |
|
|
No problem Incith. I actually have your google script in my work dir, haven't had a chance to put it into the bot yet, but it's in my pile of todo stuff
I'm sure once I do start using it, I'll be pestering you with bugreports and suggestions too, like I do with everyone else
I'm also using your horoscope script and did some minor tweaks to my local copy, didn't think they were significant enough to post about. The most significant change I made was to use:
| Code: |
catch {set http [::http::geturl "${query}daily${input}.html" -timeout [expr 1000 * 15]]} error
[..snip..]
catch {set http [::http::geturl "${query}dailychinese${input}.html" -timeout [expr 1000 * 15]]} error
[..snip..]
if {[string match -nocase "*couldn't open socket*" $error]} {
return "Error: couldn't connect..Try again later"
}
if { [::http::status $http] == "timeout" } {
[..snip..]
|
I added the catch and return error msg cos my isp's dns sucks and I've hit 'host unreachable' quite a few times in scripts.
Also had to change:
| Code: |
regsub -- "^${incith::horoscope::command_char}" $input "" input
to:
regsub -- ^\\. $input "" input
|
because I use the . char as a cmd char, and the regsub was thinking that the . was an atom so it was chopping off the 1st letter of the sign name when using .horoscope leo, for example.
Also changed this a bit to give more verbose help:
| Code: |
Original:
namespace eval horoscope {
# SEND_OUTPUT
# no point having two copies of this in public/private_message{}
#
proc send_output {input where} {
foreach line [incith::horoscope::parse_output [horoscope $input]] {
putquick "PRIVMSG $where :$line"
}
}
---
My change:
namespace eval horoscope {
# SEND_OUTPUT
# no point having two copies of this in public/private_message{}
proc send_output {input where} {
if {$input == ""} {
puthelp "PRIVMSG $where :Please choose a sign: capricorn aquarius pisces aries taurus gemini cancer leo virgo libra scorpio sagittarius rat ox tiger rabbit dragon snake horse goat monkey rooster dog pig"
return
}
set validsign 0
foreach sign [split $incith::horoscope::valid_signs " "] {
if {$input == $sign} {
set validsign 1
}
}
if {$validsign == 0} {
puthelp "PRIVMSG $where :Please choose a sign: capricorn aquarius pisces aries taurus gemini cancer leo virgo libra scorpio sagittarius rat ox tiger rabbit dragon snake horse goat monkey rooster dog pig"
return
} else {
foreach line [incith::horoscope::parse_output [horoscope $input]] {
puthelp "PRIVMSG $where :$line"
}
}
}
|
And now I've totally mucked up this topic thread <g> |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Jun 13, 2006 1:59 am Post subject: |
|
|
Hmm, now that I looked at my changes again, I just noticed a bit I can condense:
| Code: |
proc send_output {input where} {
set validsign 0
foreach sign [split $incith::horoscope::valid_signs " "] {
if {$input == $sign} {
set validsign 1
}
}
if {($validsign == 0) || ($input == "")} {
puthelp "PRIVMSG $where :Please choose a valid sign: etc etc"
return
} else {
foreach line [incith::horoscope::parse_output [horoscope $input]] {
puthelp "PRIVMSG $where :$line"
}
}
}
|
|
|
| Back to top |
|
 |
incith Master

Joined: 23 Apr 2005 Posts: 275 Location: Canada
|
Posted: Tue Jun 13, 2006 3:35 am Post subject: |
|
|
You're amazing.
If you do submit any google changes, they'd have to go to the guy I handed the script over to, madwoota.
As for horoscope.. it is probably due for an update, but weather was a priority.
I'll definitely refer back to this thread for a future horoscope release. The . problem can likely be resolved by changing the regexp to {} instead of "", but it is late, and sometimes I think I know Tcl better than I really do (which isn't that well). To be honest, I never use horoscope.. perhaps I'll wait until my luck feels a bit better.  _________________ ; Answer a few unanswered posts! |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Jun 13, 2006 5:35 am Post subject: |
|
|
| incith wrote: |
If you do submit any google changes, they'd have to go to the guy I handed the script over to, madwoota.
|
Ahh, didn't know you handed it off. I'll have to grab a more recent version (I have v1.8 in my archive)
| Quote: |
As for horoscope..
The . problem can likely be resolved by changing the regexp to {} instead of ""
|
Yep, just tried it, and it worked
Tnx  |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Jun 13, 2006 5:39 am Post subject: |
|
|
| oops, my bad, I must be tired too..It didnt work (I mis-tested it... I did .horoscope leo, the error shows when I do .leo - the 1st letter gets chopped..) Garf.. |
|
| Back to top |
|
 |
|