| View previous topic :: View next topic |
| Author |
Message |
jfb392 Voice
Joined: 08 Mar 2007 Posts: 8
|
Posted: Sun Jun 17, 2007 2:15 pm Post subject: Problem with edited Google script. |
|
|
Using the google-0.2.1 script, I attempted to make a script that finds artists on the music site Purevolume by finding the first result on Google.
| Code: | package require http
bind pub - !pv pub:pv
set agent "Mozilla"
proc pub:pv { nick uhost handle channel arg } {
global agent
if {[llength $arg]==0} {
putserv "PRIVMSG $channel :Keyword please."
} else {
set query "http://www.google.com/search?btnI=&q=purevolume&"
for { set index 0 } { $index<[llength $arg] } { incr index } {
set query "$query[lindex $arg $index]"
if {$index<[llength $arg]-1} then {
set query "$query+"
}
}
putserv "PRIVMSG $channel :$query"
set token [http::config -useragent $agent]
set token [http::geturl $query]
puts stderr ""
upvar #0 $token state
set max 0
foreach {name value} $state(meta) {
if {[regexp -nocase ^location$ $name]} {
set newurl [string trim $value]
putserv "PRIVMSG $channel :$newurl"
}
}
}
}
|
If I remove purevolume& from the line, it works just like the Google script.
However, with the purevolume& addition, I get
| Code: | | [13:00] Tcl error [pub:pv]: can't read "query": no such variable |
Is the query too long or something?
I'm really new to TCL, so it's probably a dumb mistake. |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Sun Jun 17, 2007 2:33 pm Post subject: |
|
|
| No, its how query is formatted using the http::get function. That and how you append more data into the string with set query "$query[lindex $arg $index]" Comment out that 2nd query line and it should work (assuming you do have the previous set query properly formatted. Your first line is not a proper query format, but it might work as a plain url, without the query option to geturl.. Check the manpage for tcl's http and in particular the section on query.. Plenty of example scripts around here as well.) |
|
| Back to top |
|
 |
jfb392 Voice
Joined: 08 Mar 2007 Posts: 8
|
Posted: Sun Jun 17, 2007 2:58 pm Post subject: |
|
|
Commenting out the query line doesn't seem to work.
This isn't my script, it's just by anal0uge, I just tried to plug something in.
I hardly know any TCL.
Wouldn't I call ::http::formatquery though?
Or is there anyway to take the arg and append the purevolume.com to it? |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Jun 17, 2007 4:12 pm Post subject: |
|
|
if you want to constrain google's search to a specific site, while still allowing your users the freedom search for any term on that specific site, change the section of your code to match like i've done below. | Code: | } else {
set query "http://www.google.com/search?btnI=&q="
for { set index 0 } { $index<[llength $arg] } { incr index } {
set query "$query[lindex $arg $index]"
if {$index<[llength $arg]-1} then {
set query "$query+"
}
}
append query "+site%3Apurevolume.com"
# putserv "PRIVMSG $channel :$query" # debug code?
set token [http::config -useragent $agent]
set token [http::geturl $query] |
After the query line is built normally, you can cleary see i just append "+site:purevolume.com". (: == %3a when encoding for google querys). This should accomplish your goal. enjoy
edit: as a side note, for adding other possible constraints click here
Last edited by speechles on Sun Jun 17, 2007 7:37 pm; edited 3 times in total |
|
| Back to top |
|
 |
jfb392 Voice
Joined: 08 Mar 2007 Posts: 8
|
Posted: Sun Jun 17, 2007 4:18 pm Post subject: |
|
|
Thank you speechles, I was so frustrated.
 |
|
| Back to top |
|
 |
|