Image search script for eggdrop (Bing API)

Image search script for eggdrop (Bing API)

***BING have since closed their API so this script no longer works :(

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:

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='Off'&Query='$text'"
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 &lt;= 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 :)