I am modifying a script that retrieves stock quotes from yahoo finance. It works for most symbols, such as DJI. however, some require a ^ infront of the stock, like ^IXIC . Eggdrop spits out an error when that symbol is used:
[11:49] Tcl error [pub:quote]: Illegal characters in URL path
This is the part of the script that retrieves the data:
set stock [string toupper [lindex $arg 0]]
set query "http://finance.yahoo.com/d/quotes.csv?s ... 1a3&e=.csv"
set token [http::geturl $query]
set all [http::data $token]
regsub -all \" $all "" all
set all [split $all ","]
so if $query contains a ^, it chokes. How can I get around this?
proc myproc {n u h c t} {
set myurl [string map $::mapvar $inputvar]
# geturl or whatever after translating the input (inputvar)
}
# String map basically uses pairs, the char to be changed, and then char to change it to.. Some chars are quoted to protect them or indicate they all go together. Also note the $:: above refers to global space (outside of the proc) so $::mapvar means this setting below:
set mapvar {
"\ " + : %3A \\ %5C%5C \[ %5B \] %5D \# %23 \" %22 \' %27 ! %21 @ %40 $ %24 \( %28 \) %29 ~ %7E ` %60 % %25 ^ %5E \& %26 = %3D + %2B| %7C \{ %7B \} %7D / %2F \? %3F , %2C < %3C > %3E ; %3B
}
# ignore the word wrap above, string map doesn't care as long as the var has an even number of chars/words.
Thats a good collection of strings to handle most html input, there's other examples around, much more extensive ones (look at my dictionary script in the archive for example, that has over 100 chars in its map.)
Thanks, however now I get the error
[13:55] Tcl error [pub:quote]: char map list unbalanced
I don't understand the charmap thing to debug it myself
Edit: Well after much studying of the charmap var, I realized there was a space missing in front of the | char. Also, I removed the remapping of the : and /, because I got the error Tcl error [pub:quote]: Unsupported URL: http%3A%2F%2Ffinance.yahoo.com%2Fd%2Fquotes.csv%3Fs%3D%5ESPC%26f%3Dst5l9c6p4b1a3%26e%3D.csv
Don't feed http:// to the string map and it won't mangle your input var.. Just use the url without http:// until you're giving the data to geturl (you can stuff http://$input into geturl, the http:// is always present so it can be hard-coded)
And yeah my example got word-wrapped by the forum's editor so it might've been a little messed up.