]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
imdb plugin: show popular movies acted/directed when finding people
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 4 Apr 2007 19:45:34 +0000 (19:45 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 4 Apr 2007 19:45:34 +0000 (19:45 +0000)
data/rbot/plugins/imdb.rb
data/rbot/plugins/url.rb

index d8d4dad8a52a2681d466a300a0d6dfddbf22c64c..5615ac00c4dd7e4cb07fc1a8b807738a8501d77d 100644 (file)
@@ -138,15 +138,37 @@ class Imdb
         death = "Death: #{data.ircify_html.gsub(/\s+more$/,'')}"
       end
 
-      awards = nil
-      data = grab_info("Awards", resp.body)
-      if data
-        awards = "Awards: #{data.ircify_html.gsub(/\s+more$/,'')}"
+      movies = {}
+
+      filmorate = nil
+      begin
+        filmorate = @bot.httputil.get("http://us.imdb.com" + sr + "filmorate")
+      rescue Exception
       end
 
+      if filmorate
+        filmorate.scan(/<div class="filmo">.*?<a href="\/title.*?<\/div>/m) { |str|
+          what = str.match(/<a name="[^"]+">([^<]+)<\/a>/)[1] rescue nil
+          # next unless what
+          next unless ['Actor', 'Director'].include?(what)
+          movies[what] = str.scan(/<a href="\/title\/[^"]+">([^<]+)<\/a>/)[0..2].map { |tit|
+            Utils.decode_html_entities(tit)
+          }
+        }
+      end
+      debug movies.inspect
+
       info = "#{name} : http://us.imdb.com#{sr}\n"
       info << [birth, death].compact.join('. ') << "\n"
-      info << awards if awards
+      unless movies.empty?
+        info << "Top Movies:: "
+        ar = []
+        movies.keys.sort.each { |key|
+          ar << key.dup
+          ar.last << ": " + movies[key].join(', ')
+        }
+        info << ar.join('. ')
+      end
       return info
 
     end
index 95ccb5d95dcdc2f8504efc70066cab10d3abf04d..f3eb3a7f506237e2f68d574e34e872b9de835987 100644 (file)
@@ -60,9 +60,9 @@ class UrlPlugin < Plugin
         # in the first case we download the initial part and the parse it; in the second
         # case we only download as much as we need to find the title
         if @bot.config['url.first_par']
-          first_par = Utils.ircify_first_html_par(body)
-          extra << "\n#{LINK_INFO} text: #{first_par}" unless first_par.empty?
           title = get_title_from_html(body)
+          first_par = Utils.ircify_first_html_par(body, :strip => title)
+          extra << "\n#{LINK_INFO} text: #{first_par}" unless first_par.empty?
           return "title: #{title}#{extra}" if title
         else
           title = get_title_from_html(body)