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 

Google search
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 398

PostPosted: Fri Mar 19, 2021 12:13 am    Post subject: Google search Reply with quote

So was trying to make a Google search script, which eould retrieve the URL and Title of the search term, (this is my first time messing with http and websites)
Code:

bind PUB - "!google" ct:google

package require http
package require tls

proc ct:google {nick host hand chan text} {
   set token [http::geturl https://www.google.com/search?q=[join $text +] -timeout 9000]
   set data [http::data $token]
   putserv "PRIVMSG $chan :$data"
}

So i also need to figure out how to make it for https/tls as google only works that way, if i use a http link for $token it dumps a pile of http code so, again i will try working on it tomorrow, but will appreciate any/all help Wink I noticed other web scripts use regex, but again i am trying to figure that out heh Laughing
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1108
Location: France

PostPosted: Fri Mar 19, 2021 5:14 am    Post subject: Reply with quote

Loading tls package but not using it...

Code:
bind PUB - "!google" ct:google

package require http
package require tls

proc ct:google {nick host hand chan text} {
   http::register https 443 [list ::tls::socket]
   set token [http::geturl https://www.google.com/search?q=[join $text +] -timeout 9000]
   set data [http::data $token]
   putserv "PRIVMSG $chan :$data"
   http::unregister https
}

_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 398

PostPosted: Fri Mar 19, 2021 10:40 am    Post subject: Reply with quote

oh, lmfao, thanks CrazyCat, i'll test it right away Wink


EDIT

just tested it and when i do !google lego ,i get this weird code
Code:

ComputerTech_ !google lego
Tech <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">

_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1108
Location: France

PostPosted: Fri Mar 19, 2021 11:08 am    Post subject: Reply with quote

It's not weird, it's the html code of the google result page, as if you displayed the source code.
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 398

PostPosted: Fri Mar 19, 2021 1:03 pm    Post subject: Reply with quote

Oh, i see, i didn't realise that lol.

Will try see how to convert the html code into readable then Laughing
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 398

PostPosted: Sat Mar 20, 2021 5:09 pm    Post subject: Reply with quote

Okay, finally got a working version
Code:

######################################################################################
# CT-Google.tcl
######################################################################################
#Author    ComputerTech
#IRC       Irc.DareNet.Org  #ComputerTech
#Email     ComputerTech@DareNet.Org
#GitHub    https://github.com/computertech312
#Version   0.1
#Released  20/03/2021
######################################################################################
# Description:
#
#               An Elaborate Google Search Script
#               
#
# Credits:
#
#               Special thanks to launchd, spyda and CrazyCat
#               
#
# History:
#
#               - 0.1: First release.
#
######################################################################################
# Start Of Configuration #
##########################
# Set trigger of the script.
##
set ctgg(trig) "!google"

###################
# Set flag for Commands.
##
# Owner     = n
# Master    = m
# Op        = o
# Voice     = v
# Friend    = f
# Everyone  = -
##
set ctgg(flag) "ofmn"

###################
# Set API Key
##
set ctgg(api) "Your-API-Key-Here"

##################
# Set to use Notice Or Privmsg for Output of Commands
##
# 0 = Notice
# 1 = Privmsg
# 2 = Channel
##
set ctcmd(msg) "0"

########################
# End Of Configuration #
######################################################################################

bind PUB $ctgg(flag) $ctgg(trig) goo:gle

package require json
package require tls
package require http

proc goo:gle {nick host hand chan text} {
   global ctgg
   set google "\0032G\003\0034o\003\0038o\003\0032g\003\0033l\003\0034e\003"
   http::register https 443 [list ::tls::socket]
   set url "https://www.googleapis.com/customsearch/v1?key=$ctgg(api)&cx=016496445636816056556:qvzl4ib4xtb&q=[join $text +]"
     set data "[http::data [http::geturl "$url" -timeout 10000]]"
     set datadict [::json::json2dict $data]
     set items [dict get $datadict "items"]
       set item [lindex $items 0]
        set title [dict get $item "title"]
         set link [dict get $item "link"]
           set info [dict get $item "snippet"]
        switch -- $ctgg(msg) {
        "0" {set ctgg(output) "NOTICE $nick"}
        "1" {set ctgg(output) "PRIVMSG $nick"}
        "2" {set ctgg(output) "PRIVMSG $chan"}
        }
    }
     putserv "$ctgg(output) :$google $title / $link / $info"
  http::unregister https
}
######################################################################################

It's working perfectly, but i plan to add much more things Wink

Any ideas are much appreciated Razz
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1108
Location: France

PostPosted: Sat Mar 20, 2021 6:44 pm    Post subject: Reply with quote

Don't use:
Code:
set url "https://www.googleapis.com/customsearch/v1?key=$ctgg(api)&cx=016496445636816056556:qvzl4ib4xtb&q=[join $text +]"
set data "[http::data [http::geturl "$url" -timeout 10000]]"


Better use:
Code:
set uargs [http::formatQuery key $ctgg(api) cx 016496445636816056556:qvzl4ib4xtb q $text]
set data [http::data [http::geturl "https://www.googleapis.com/customsearch/v1" -query $uargs -timeout 10000]]

_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.


Last edited by CrazyCat on Sun Mar 21, 2021 3:27 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 398

PostPosted: Sat Mar 20, 2021 9:02 pm    Post subject: Reply with quote

Getting this error with your code CrazyCat
Code:

<Tech> [01:01:29] Tcl error [goo:gle]: invalid command name "http::formatquery"

Code
Code:

######################################################################################
# CT-Google.tcl
######################################################################################
#Author    ComputerTech
#IRC       Irc.DareNet.Org  #ComputerTech
#Email     ComputerTech@DareNet.Org
#GitHub    https://github.com/computertech312
#Version   0.2
#Released  21/03/2021
######################################################################################
# Description:
#
#               - An Elaborate Google Search Script.
#               - After 100 usages of the script, it will automatically stop until the next day.
#               - Grab your own API key from here - https://developers.google.com/custom-search/v1/overview
#
# Credits:
#
#               - Special thanks to launchd, spyda and CrazyCat.
#               - Usage of m00nies throttle control.
#             
# History:
#
#               - 0.1: First release.
#
######################################################################################
# Start Of Configuration #
##########################
# Set trigger of the script.
##
set ctgg(trig) "!google"

###################
# Set flag for Commands.
##
# Owner     = n
# Master    = m
# Op        = o
# Voice     = v
# Friend    = f
# Everyone  = -
##
set ctgg(flag) "ofmn"

###################
# Set API Key
##
set ctgg(api) "API-KERE-HERE"

##################
# Set to use Notice Or Privmsg for Output of Commands
##
# 0 = Notice
# 1 = Privmsg
# 2 = Channel
##
set ctgg(msg) "2"


########################
# End Of Configuration #
######################################################################################

bind PUB $ctgg(flag) $ctgg(trig) goo:gle
bind time - "00 00 * * *" api:reset

package require json
package require tls
package require http

proc goo:gle {nick host hand chan text} {
   global ctgg
 if {![info exists google]} {
   set google "\0032G\003\0034o\003\0038o\003\0032g\003\0033l\003\0034e\003"
}
 if {![info exists ctgg(count)]} {
        set ctgg(count) "0"
 }
 if {$ctgg(count) == "100"} {
    puthelp "$ctgg(output) :Max uses of API exceeded."
    return 1
 }
        switch -- $ctgg(msg) {
        "0" {set ctgg(output) "NOTICE $nick"}
        "1" {set ctgg(output) "PRIVMSG $nick"}
        "2" {set ctgg(output) "PRIVMSG $chan"}
        }
   http::register https 443 [list ::tls::socket]
set uargs [http::formatquery key $ctgg(api) cx 016496445636816056556:qvzl4ib4xtb q $text]
set data [http::data [http::geturl "https://www.googleapis.com/customsearch/v1" -query $uargs -timeout 10000]]
   if {[string length $data] == 0} {
     puthelp "$ctgg(output) :API key Returned no Data" ;return 1 }
     set datadict [::json::json2dict $data]
     set items [dict get $datadict "items"]
       set item [lindex $items 0]
        set title [dict get $item "title"]
         set link [dict get $item "link"]
         set info [dict get $item "snippet"]
     putserv "$ctgg(output) :$google $title / $link / $info"
     incr ctgg(count) 1
  http::unregister https
}
proc api:reset {min hour day month weekday} {
   global ctgg
unset ctgg(count)
}
######################################################################################

_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1108
Location: France

PostPosted: Sun Mar 21, 2021 3:29 am    Post subject: Reply with quote

My bad, formatQuery with a capital Q.
I corrected my previous post.
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Goga
Halfop


Joined: 19 Sep 2020
Posts: 82

PostPosted: Sat Mar 27, 2021 5:03 am    Post subject: Reply with quote

Code:
######################################################################################
# CT-Google.tcl
######################################################################################
#Author    ComputerTech
#IRC       Irc.DareNet.Org  #ComputerTech
#Email     ComputerTech@DareNet.Org
#GitHub    https://github.com/computertech312
#Version   0.3
#Released  21/03/2021
######################################################################################
# Description:
#
#               - An Elaborate Google Search Script.
#               - After 100 usages of the script, it will automatically stop until the next day.
#               - Grab your own API key from here
#                 https://developers.google.com/custom-search/v1/overview
#               - And a Engine ID from here
#                 https://cse.google.com/cse/
#
# Credits:
#
#               - Special thanks to launchd, spyda and CrazyCat.
#             
# History:
#
#               - 0.3: Added Max results option.
#               - 0.2: Fixed a few minor bugs.
#               - 0.1: First release.
#
######################################################################################
# Start Of Configuration #
##########################
# Set trigger of the script.
##
set ctgg(trig) "!google"


###################
# Set flag for Commands.
##
# Owner     = n
# Master    = m
# Op        = o
# Voice     = v
# Friend    = f
# Everyone  = -
##
set ctgg(flag) "ofmn"


###################
# Set API Key
##
set ctgg(api) "KeyGiven"


##################
# Set Engine ID
##
set ctgg(id) "KeyGiven"


##################
# Set to use Notice Or Privmsg for Output of Commands
##
# 0 = Notice
# 1 = Privmsg
# 2 = Channel
##
set ctgg(msg) "2"


##################
# Set amount of results to output
##
set ctgg(max) "3"


########################
# End Of Configuration #
######################################################################################

bind PUB $ctgg(flag) $ctgg(trig) goo:gle

package require json
package require tls
package require http

proc goo:gle {nick host hand chan text} {
   global ctgg
   set google "\0032G\0034o\0038o\0032g\0033l\0034e\003"
   http::register https 443 [list ::tls::socket]
     set url "https://www.googleapis.com/customsearch/v1?key=$ctgg(api)&cx=$ctgg(id)&q=[join $text +]"
     set data "[http::data [http::geturl "$url" -timeout 10000]]"
     set datadict [::json::json2dict $data]
     set items2 [dict get $datadict "searchInformation"]
     set items [dict get $datadict "items"]
for {set i 0} {$i < $ctgg(max)} {incr i} {
     set item [lindex $items $i]
     set title [dict get $item "title"]
     set link [dict get $item "link"]
     set info [dict get $item "snippet"]
     set time [dict get $items2 "formattedSearchTime"]
     set total [dict get $items2 "formattedTotalResults"]
     switch -- $ctgg(msg) {
        "0" {set ctgg(output) "NOTICE $nick"}
        "1" {set ctgg(output) "PRIVMSG $nick"}
        "2" {set ctgg(output) "PRIVMSG $chan"}
     }
     putserv "$ctgg(output) :$google  About $total results ($time seconds)"
     putserv "$ctgg(output) :$google  $title / $link / $info"
  http::unregister https
  http::cleanup $data
  }
putlog "{$google}.tcl v0.3 by ComputerTech Loaded"
}

This is ComputerTech's !Google TCL I am getting this error:

Tcl error [goo:gle]: key "searchInformation" not known in dictionary

help please.
Back to top
View user's profile Send private message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 398

PostPosted: Sat Mar 27, 2021 2:24 pm    Post subject: Reply with quote

Try this, it works perfectly here Wink
Code:

######################################################################################
# CT-Google.tcl
######################################################################################
#Author    ComputerTech
#IRC       Irc.DareNet.Org  #ComputerTech
#Email     ComputerTech@DareNet.Org
#GitHub    https://github.com/computertech312
#Version   0.3
#Released  21/03/2021
######################################################################################
# Description:
#
#               - An Elaborate Google Search Script.
#               - After 100 usages of the script, it will automatically stop until the next day.
#               - Grab your own API key from here
#                 https://developers.google.com/custom-search/v1/overview
#               - And a Engine ID from here
#                 https://cse.google.com/cse/
#
# Credits:
#
#               - Special thanks to launchd, spyda and CrazyCat.
#
# History:
#
#               - 0.3: Added Max results option.
#               - 0.2: Fixed a few minor bugs.
#               - 0.1: First release.
#
######################################################################################
# Start Of Configuration #
##########################
# Set trigger of the script.
##
set ctgg(trig) "!google"


###################
# Set flag for Commands.
##
# Owner     = n
# Master    = m
# Op        = o
# Voice     = v
# Friend    = f
# Everyone  = -
##
set ctgg(flag) "-"


###################
# Set API Key
##
set ctgg(api) "Your-API-Key"


##################
# Set Engine ID
##
set ctgg(id) "Your-Engine-ID"


##################
# Set to use Notice Or Privmsg for Output of Commands
##
# 0 = Notice
# 1 = Privmsg
# 2 = Channel
##
set ctgg(msg) "2"


##################
# Set amount of results to output
##
set ctgg(max) "3"


########################
# End Of Configuration #
######################################################################################

bind PUB $ctgg(flag) $ctgg(trig) goo:gle

package require json
package require tls
package require http

proc goo:gle {nick host hand chan text} {
   global ctgg google
   set ::google "\00302G\00304o\00308o\00302g\00303l\00304e\003"
   http::register https 443 [list ::tls::socket]
   set url "https://www.googleapis.com/customsearch/v1?key=$ctgg(api)&cx=$ctgg(id)&q=[join $text +]"
   set data "[http::data [http::geturl "$url" -timeout 10000]]"
    http::cleanup $data
   set datadict [::json::json2dict $data]
   set items2 [dict get $datadict "searchInformation"]
          switch -- $ctgg(msg) {
         "0" {set ctgg(output) "NOTICE $nick "}
         "1" {set ctgg(output) "PRIVMSG $nick"}
         "2" {set ctgg(output) "PRIVMSG $chan"}
      }
    set time [dict get $items2 "formattedSearchTime"]
    set total [dict get $items2 "formattedTotalResults"]
    putserv "$ctgg(output) :$google  About $total results ($time seconds)"
    set items [dict get $datadict "items"]
   for {set i 0} {$i < $ctgg(max)} {incr i} {
      set item [lindex $items $i]
      set title [dict get $item "title"]
      set link [dict get $item "link"]
      set info [dict get $item "snippet"]
      putserv "$ctgg(output) : $title / $link / $info"
   }
      http::unregister https
}
putlog "$::google.tcl v0.3 by ComputerTech Loaded"
######################################################################################


Code:

CT !google eggdrop irc bot
 Tech Google  About 40,200 results (0.36 seconds)
 Tech  Eggdrop / https://www.eggheads.org/ / Eggdrop is the oldest Internet Relay Chat (IRC) bot still in active development.
 Tech  Eggdrop - Wikipedia / https://en.wikipedia.org/wiki/Eggdrop / It was originally written by Robey Pointer in December 1993 to help manage and
 Tech  eggheads/eggdrop: The Eggdrop IRC Bot - GitHub / https://github.com/eggheads/eggdrop / Jul 2, 2016 ... The Eggdrop IRC Bot. Contribute to eggheads/eggdrop development by creating

_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Sat Mar 27, 2021 5:21 pm    Post subject: Reply with quote

oh thats weird im gettin this :

Quote:

<!doctype html><html itemscope="" itemtype="http://schema.org/SearchResultsPage" lang="en"><head><meta charset="UTF-8"><meta content="origin" name="referrer"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>eggdrop irc bot - Google Search</title><script nonce="cHq6NVRRsXiPVm7hMKyhWA==">(function(){window.google={kEI:'0aFfYJ2TDruv0PEPzOubwAU',kEXPI:'31',kBL:'jmEJ'};google.sn='web';google.kHL='en';})();(function(){
Back to top
View user's profile Send private message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 398

PostPosted: Sat Mar 27, 2021 5:23 pm    Post subject: Reply with quote

got the latest version of the http, json, tcl and tls package? because it works here Laughing

Thats the only things i can think would affect

Also what did you search? it might not be full proof from weird searches, like !google {foo}
_________________
ComputerTech


Last edited by ComputerTech on Sat Mar 27, 2021 5:25 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
simo
Revered One


Joined: 22 Mar 2015
Posts: 1027

PostPosted: Sat Mar 27, 2021 5:24 pm    Post subject: Reply with quote

oh it needs API i dont have that yet only been using YT API
Back to top
View user's profile Send private message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 398

PostPosted: Sat Mar 27, 2021 5:26 pm    Post subject: Reply with quote

ah, you can find the custom search api from the same google api console Wink

(Instructions in Description)


Future Note: i am going to remove the api option soon and hopefully "scrape" from the google
search engine, like incith once did Razz
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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