Bing web search

By FordLawnmower on Feb 08, 2013

Searches bing.com and returns results to irc.
Requested in #Script-Help on irc.geekshed.net by ratdog
ScreenShot:
Image

  • This is a bot script and should be loaded into a second client for normal use of the !triggers.
  • If you want to use this for a personal script; Right click channel or status, and turn the "bingsearch Trigger" OFF.
  • You can then use the "/bing" alias to echo the results to your screen.
    Channel Control:
  • +bing to turn the script ON for a channel. (requires ops)
  • -bing to turn the script OFF for a channel. (requires ops)
    Triggers:
  • !bing , @bing
  • !bing will notice the user
  • @bing will message the channel if the user is voiced or higher
  • Defaults to notice
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;                               Bing search by Ford_Lawnmower irc.geekshed.net #Script-Help                                              ;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
alias -l Getbingsearch {
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;Start of Simple Setup;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;Change %logo to the logo you want at the start of each line
  var %logo $+($chr(3),02,$chr(44),07,$chr(2),Bing,$chr(15))
  ;Change %maxresults to the number of results you want 1 to 8
  var %maxresults 4
  ;Change %textcolor to the color you want normal text
  var %textcolor $+($chr(3),04)
  ;Change %linkcolor to the color you want for links
  var %linkcolor $+($chr(31))
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;End Setup;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;      
  $1-2 $+(%textcolor,Searching) %logo ........
  var %sockname $+(bingsearch,$network,$2,$ticks)
  sockopen %sockname www.bing.com 80
  svar %sockname output $1-2
  svar %sockname get $+(/search?q=,$urlencode($3-))
  svar %sockname logo %logo
  svar %sockname maxresults %maxresults
  svar %sockname textcolor %textcolor
  svar %sockname linkcolor %linkcolor
}
menu Channel,Status {
  .$iif($group(#bingsearch) == On,$style(1)) bingsearch Trigger
  ..$iif($group(#bingsearch) == On,$style(2)) On: .enable #bingsearch
  ..$iif($group(#bingsearch) == Off,$style(2)) Off: .disable #bingsearch
}
#bingsearch on
On $*:Text:/^(\+|-|!|@)bing.*/Si:#: {
  var %action $regml(1)
  if (%action isin +-) && ($regex($nick($chan,$nick).pnick,/(!|~|&|@)/)) {
    if (%action == +) {
      if ($istok(%bingsearchChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is already running the bingsearch script }
      else { 
        .enable #bingsearch
        Set %bingsearchChanList $addtok(%bingsearchChanList,$+($network,$chan),32)
        .msg $chan $nick has activated the bingsearch script for $chan .
      }
    }
    else {
      if (!$istok(%bingsearchChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is not running the bingsearch script }
      else { 
        Set %bingsearchChanList $remtok(%bingsearchChanList,$+($network,$chan),1,32)
        .msg $chan $nick has deactivated the bingsearch script for $chan . 
      }
    }
  }
  elseif (!$timer($+(bingsearch,$network,$nick))) && ($istok(%bingsearchChanList,$+($network,$chan),32)) {
    .timer $+ $+(bingsearch,$network,$nick) 1 6 noop
    var %method $iif(%action == !,.notice $nick,$iif($regex($nick($chan,$nick).pnick,/(!|~|&|@|%|\+)/),.msg $chan,.notice $nick))
    Getbingsearch %method $2-
  }
}
#bingsearch end
alias bing { Getbingsearch echo -a $1- }
On *:sockopen:bingsearch*: {
  if (!$sockerr) {
    sockwrite -nt $sockname GET $svar($sockname,get) HTTP/1.0
    sockwrite -n $sockname Host: www.bing.com
    sockwrite -n $sockname $crlf
  }
  else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
}
On *:sockread:bingsearch*: {
  if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  else {
    sockread -fn &bing
    if $bvar(&bing, 0) {
      bwrite $+($sockname,.dat) -1 -1 &bing
      if ($bfind(&bing, 1, </html>)) {
        bread $+($sockname,.dat) 1 $file($+($sockname,.dat)).size &bing
        .remove $+($sockname,.dat)
        var %count 1
        while ($bintween(&bing, "sb_tlst"><h3><a href=, </a></h3>, %count)) {
          noop $regex(result,$v1,/"(.*?)".*">(.*)/i)
          put $svar($sockname,output) $svar($sockname,logo) $replace($+($svar($sockname,textcolor),$Xchr($regml(result,2))) $&
          $+($chr(15),$svar($sockname,linkcolor),$regml(result,1)),<strong>,$chr(2),</strong>,$chr(2))
          if (%count == $svar($sockname,maxresults)) return
          inc %count
        }
      }
    }
  }
}
alias -l urlencode return $regsubex($1-,/([^a-z0-9])/ig,% $+ $base($asc(\t),10,16,2))
alias -l Svar {
  var %sockname $1, %item $2
  if ($isid) {
    if ($regex($sock(%sockname).mark,/ $+ %item $+ \x01([^\x01]*)/i)) return $regml(1)
  }
  elseif ($3)  {
    var %value $3-
    if (!$regex($sock(%sockname).mark,/ $+ %item $+ \x01/i)) { sockmark %sockname $+($sock(%sockname).mark,$chr(1),%item,$chr(1),%value) }
    else { sockmark %sockname $regsubex($sock(%sockname).mark,/( $+ %item $+ \x01[^\x01]*)/i,$+(%item,$chr(1),%value)) }
  }
}
alias -l Xchr { 
  var %return $regsubex($regsubex($1-,/&#x([A-F0-9]{1,2});/g,$chr($base($regml(\n),16,10))),/&#([0-9]{2});/g,$chr(\1)) 
  return $replacecs(%return,&ndash;,,&middot;,·,&raquo;,»,&laquo;,«,&Uuml;,Ü,&uuml;,ü,&Aacute;,Á,&aacute;,á,&Eacute;,$&
    É,&eacute;,é,&Iacute;,Í,&iacute;,í,&Oacute;,Ó,&oacute;,ó,&Ntilde;,Ñ,&ntilde;,ñ,&Uacute;,Ú,&uacute;,ú,&nbsp;,$chr(32),$&
    &aelig;,æ,&quot;,",&lt;,<,&gt;,>, &amp;,&)
}
alias -l Put {
  if (!$regex($1,/(\.|^)(msg|notice|echo)$/Si)) || (!$3) { echo -st **Put error** Syntax /Put msg #channel text - or - /Put notice nickname text  | return }
  tokenize 32 $regsubex($1-,/([$\|%\[\]][^\s]*)/g,$+($chr(2),$chr(2),\t))
  var %tokens $0, %Tstart 3, %Dtimer 1500
  if ($timer($+(Put,$2,$network)).secs) { %Dtimer = $calc($v1 * 1000) }  
  while ($len($($+($,%Tstart,-,%tokens),2)) > 430) {
    dec %tokens
    if ($len($($+($,%Tstart,-,%tokens),2)) <= 430) {
      .timer -m 1 %Dtimer $1-2 $($+($,%Tstart,-,%tokens),2))
      inc %Dtimer 1500
      %Tstart = $calc(%tokens + 1)
      %tokens = $0
    }
  }
  .timer -m 1 %Dtimer $1-2 $($+($,%Tstart,-,%tokens),2))
  .timer $+ $+(Put,$2,$network) -m 1 $calc(%Dtimer + 1500) noop 
}
alias -l bintween {
  var %count = 1, %mark = 0, %mark2 = 0
  while (%count <= $4) {
    if ($bfind($1, %mark2, $2).text) {
      %mark = $calc($bfind($1, %mark2, $2).text + $len($2))
      if ($bfind($1, %mark, $3).text) {
        %mark2 = $bfind($1, %mark, $3).text
      }
      else { return 0 } 
    }
    else { return 0 }
    inc %count
  }
  return $bvar($1, $iif(%mark > 0,%mark,1), $iif($calc(%mark2 - %mark) < 4130,$calc(%mark2 - %mark),4130)).text
}

Comments

Sign in to comment.
dma   -  Dec 17, 2015

sorry no longer working

 Respond  
^WeSt   -  Aug 30, 2014

Does not working , propably needs update at some point on line 80 the while cannot proceed..

mirc 7.36

 Respond  
Conscious   -  Feb 09, 2013

Dear god why?!

Sorasyn  -  Feb 09, 2013

???

Conscious  -  Feb 09, 2013

Screen scraping bing xD

FordLawnmower  -  Feb 09, 2013

I don't use bing personally, but for those who do, they can bring the same search results to irc.
Search engines are a big business and this affects the order of the results.
This was a requested script as posted in the introduction.

[18:38:56] <+ratdog> Bing! has now been rated better than google in very recent blind tests according to sofpedia article. I would like help writing a Bing! search socket for a chanel for mIRC.
This link shows some validity to this: http://www.ebizmba.com/articles/search-engines
Just looking at the alexa stats, bing is 2nd.

BlueThen  -  Feb 09, 2013

I tried out Bing's blind test - http://www.bingiton.com/?form=BIOBIP&publ=BNPSERP&crea=769

Google won 3 to 2 for me.

Conscious  -  Feb 09, 2013

Am I missing something or is bingiton just redirecting to bing?

BlueThen  -  Feb 10, 2013
Conscious  -  Feb 10, 2013

[14:38:56.698] GET http://www.bingiton.com/ [HTTP/1.1 301 Moved Permanently 323ms]
[14:38:57.047] GET http://www.bing.com/ [HTTP/1.1 200 OK 396ms]

Hawkee  -  Feb 10, 2013

I chose Google 100% of the time. Bing just doesn't offer enough specific results for development related queries.

Sorasyn  -  Feb 10, 2013

2:1:2 Google:Draw:Bing -- Bing didn't do very well regarding C#/.NET queries, which is ironic because Bing = Microsoft = .NET = C#. Lol.

BlueThen  -  Feb 11, 2013

@Hawkee I had the same trend. All 3 of the things that Google won were development related.

I understand Google uses ad data on people to help filter results, so I wonder if Bing allows that in their bingiton challenge.

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.