This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Problem with edited Google script.

Help for those learning Tcl or writing their own scripts.
Post Reply
j
jfb392
Voice
Posts: 8
Joined: Thu Mar 08, 2007 8:29 pm

Problem with edited Google script.

Post by jfb392 »

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: Select all

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: Select all

[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.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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.)
j
jfb392
Voice
Posts: 8
Joined: Thu Mar 08, 2007 8:29 pm

Post by jfb392 »

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. :oops:
Wouldn't I call ::http::formatquery though?
Or is there anyway to take the arg and append the purevolume.com to it?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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: Select all

 } 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 :D

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.
j
jfb392
Voice
Posts: 8
Joined: Thu Mar 08, 2007 8:29 pm

Post by jfb392 »

Thank you speechles, I was so frustrated.
:D
Post Reply