Image search script for eggdrop (Bing API)

Sadly one of the few APIs that still provides access to image search now the Bing API provides all the results for this script. Again a very simple script (it has a simple function? :)) Users can trigger and image search with an !images some query command just like the example below:

images

 

You can grab the script from [here]

And it looks something like this:

# Name m00nie-image
# Description Grabs bing images using its JSON API
# Version 2.0 – Works again on Bings new auth….
# 1.2 – Tidying up/https
# 1.1 – Display changes
# 1.0 – Initial release
# Website https://www.m00nie.com
# Notes Grab you own API key:
# http://datamarket.azure.com/dataset/bing/search
#
# I have had some issues around this script and
# the tcl tls lib version. At the moment tested
# working on tcltls 1.6 on Fedora 22…More
# testing on the way
################################################################

namespace eval m00nie {
namespace eval image {
package require http
package require json
package require base64
package require tls
bind pub – !images m00nie::image::search
variable version “2.0”
::http::config -useragent “Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36”
variable key “–PUT-YOUR-OWN-IN–”
http::register https 443 tls::socket

proc search {nick uhost hand chan text} {
regsub -all — { } $text {%20} text
set url “https://api.datamarket.azure.com/Bing/Search/v1/Image?\$top=5&\$format=json&Adult=%27Off%27&Query=%27$text%27”
puthelp “PRIVMSG $chan :[getinfo $nick $chan $url]”
}

proc getinfo {nick chan url} {
putlog “m00nie::image::getinfo is running”
dict set hdr Authorization “Basic [::base64::encode $m00nie::image::key:$m00nie::image::key]”
for { set i 1 } { $i <= 5 } { incr i } {
set rawpage [::http::data [::http::geturl “$url” -timeout 5000 -headers $hdr]]
if {[string length $rawpage] > 0} { break }
}
if {[string length $rawpage] == 0} { error “Bing returned no data 🙁 or we couldnt connect properly” }

set data [dict get [json::json2dict $rawpage] d results]
set output “Results:”
for { set x 0 } { $x <= 4 } { incr x } {
set title [lindex $data $x 5]
set link [lindex $data $x 7]
append output “\002” $title “\002 – ” $link ” | ”
}
return $output
}
}
}
putlog “m00nie::image $m00nie::image::version loaded”

 

Enjoy

m00nie 🙂

Comments

  • Hey, just wanted to see if there’s a more up to date version of this, as I can’t seem to get it to work. Every time I attempt an image search I get the “Bing returned no data 🙁 or we couldnt connect properly”. I’ve made sure to have all deps installed. Thanks

  • Hi random4t4x14

    I did have some issues getting this working originally after they updated the API but it does work as is for me at the moment using tcltls 1.6 on Fedora 22. What version of tcltls and OS are us using?
    Cheers

    m00nie

  • I’m using tcl-tls1.6 on Debian Wheezy x86-64, I have other scripts that use tcl-tls to do their thing, and they don’t seem to choke like this one does. I have correctly entered my API key, and I have not modified the script in anyway otherwise.