egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with edited Google script.

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
jfb392
Voice


Joined: 08 Mar 2007
Posts: 8

PostPosted: Sun Jun 17, 2007 2:15 pm    Post subject: Problem with edited Google script. Reply with quote

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
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sun Jun 17, 2007 2:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
jfb392
Voice


Joined: 08 Mar 2007
Posts: 8

PostPosted: Sun Jun 17, 2007 2:58 pm    Post subject: Reply with quote

Commenting out the query line doesn't seem to work. Confused

This isn't my script, it's just by anal0uge, I just tried to plug something in.
I hardly know any TCL. Embarassed
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
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Jun 17, 2007 4:12 pm    Post subject: Reply with quote

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 Very Happy

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
View user's profile Send private message
jfb392
Voice


Joined: 08 Mar 2007
Posts: 8

PostPosted: Sun Jun 17, 2007 4:18 pm    Post subject: Reply with quote

Thank you speechles, I was so frustrated.
Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber