]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
search: gcalc fix
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 14 Oct 2010 09:16:02 +0000 (11:16 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 14 Oct 2010 09:16:02 +0000 (11:16 +0200)
Google changed their HTML again, breaking gcalc. Fix by using the WAP
search and get the first result if it contains an equal sign.

data/rbot/plugins/search.rb

index dc5259292721468b8fdcc2cf4aeaeeb742b2c90e..4e13f3e7f7ec7dd9d539a655f5b56400fc48afbe 100644 (file)
@@ -172,7 +172,7 @@ class SearchPlugin < Plugin
     searchfor = CGI.escape(what)
 
     debug "Getting gcalc thing: #{searchfor.inspect}"
-    url = GOOGLE_SEARCH + searchfor
+    url = GOOGLE_WAP_SEARCH + searchfor
 
     begin
       html = @bot.httputil.get(url)
@@ -183,17 +183,16 @@ class SearchPlugin < Plugin
 
     debug "#{html.size} bytes of html recieved"
 
-    results = html.scan(GOOGLE_CALC_RESULT)
-    debug "results: #{results.inspect}"
+    intro, result, junk = html.split(/\s*<br\/>\s*/, 3)
+    debug "result: #{result.inspect}"
 
-    if results.length != 1
+    unless result.include? '='
       m.reply "couldn't calculate #{what}"
       return
     end
 
-    result = results[0][0].ircify_html
     debug "replying with: #{result.inspect}"
-    m.reply "#{result}"
+    m.reply result.ircify_html
   end
 
   def gcount(m, params)