]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
search: fix gcalc
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 25 Jan 2012 08:44:40 +0000 (09:44 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 25 Jan 2012 08:44:44 +0000 (09:44 +0100)
Google changed their layout again. To be a little more future-proof,
split the html into as many <br/> sections as there are, and pick the
first one that contains the literal string ' = ' if there is one.

data/rbot/plugins/search.rb

index 60a70c54eed2d2cdee97f5be6289be338e02454f..2a1b3dc1c6777b017d88c52cb879c02775c65620 100644 (file)
@@ -183,13 +183,15 @@ class SearchPlugin < Plugin
 
     debug "#{html.size} bytes of html recieved"
 
-    intro, result, junk = html.split(/\s*<br\/>\s*/, 3)
-    debug "result: #{result.inspect}"
+    splits = html.split(/\s*<br\/>\s*/)
+    candidates = splits.select { |section| section.include? ' = ' }
+    debug "candidates: #{candidates.inspect}"
 
-    unless result.include? '='
+    if candidates.empty?
       m.reply "couldn't calculate #{what}"
       return
     end
+    result = candidates.first
 
     debug "replying with: #{result.inspect}"
     m.reply result.ircify_html