X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Ffreshmeat.rb;h=3ae887d1714d6fe0a43efdb8db7e74c8c0027986;hb=16336b4a240a4265d1f2df1e30d7b68d3a924287;hp=5a045123256e72fc35b617b83078696e94102e40;hpb=b11c3c4042b03e36639370002ecf86c44f7ddde4;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/freshmeat.rb b/data/rbot/plugins/freshmeat.rb index 5a045123..3ae887d1 100644 --- a/data/rbot/plugins/freshmeat.rb +++ b/data/rbot/plugins/freshmeat.rb @@ -1,27 +1,61 @@ +#-- vim:sw=2:et +#++ +# +# :title: Freshmeat plugin for rbot + require 'rexml/document' -require 'uri/common' class FreshmeatPlugin < Plugin include REXML def help(plugin, topic="") "freshmeat search [=4] => search freshmeat for , freshmeat [=4] => return up to freshmeat headlines" end - + + REL_ENTRY = %r{(.*?)} + PRJ_ENTRY = %r{(.*?)} + + # This method defines a filter for fm pages. It's needed because the generic + # summarization grabs a comment, not the actual article. + # + def freshmeat_filter(s) + loc = Utils.check_location(s, /freshmeat\.net/) + return nil unless loc + entries = [] + s[:text].scan(/#{REL_ENTRY}|#{PRJ_ENTRY}/) { |m| + entry = { + :type => ($1 || $4).dup, + :code => ($2 || $5).dup, + :name => ($3 || $6).dup + } + entries << entry + } + return nil if entries.empty? + title = s[:text].ircify_html_title + content = entries.inject([]) { |l, e| l << e[:name] }.join(" | ") + return {:title => title, :content => content} + end + + def initialize + super + @bot.register_filter(:freshmeat, :htmlinfo) { |s| freshmeat_filter(s) } + end + def search_freshmeat(m, params) max = params[:limit].to_i search = params[:search].to_s max = 8 if max > 8 - begin - xml = @bot.httputil.get("http://freshmeat.net/search-xml/?orderby=locate_projectname_full_DESC&q=#{URI.escape(search)}") - rescue URI::InvalidURIError, URI::BadURIError => e - m.reply "illegal search string #{search}" - return - end + xml = @bot.httputil.get("http://freshmeat.net/search-xml/?orderby=locate_projectname_full_DESC&q=#{CGI.escape(search)}") unless xml m.reply "search for #{search} failed" return end - doc = Document.new xml + doc = nil + begin + doc = Document.new xml + rescue + debug xml + error $! + end unless doc m.reply "search for #{search} failed" return @@ -54,12 +88,12 @@ class FreshmeatPlugin < Plugin m.reply reply } end - + def freshmeat(m, params) max = params[:limit].to_i max = 8 if max > 8 begin - xml = @bot.httputil.get('http://images.feedstermedia.com/feedcache/ostg/freshmeat/fm-releases-global.xml') + xml = @bot.httputil.get('http://freshmeat.net/backend/fm-releases-global.xml') unless xml m.reply "freshmeat news parse failed" return @@ -79,8 +113,8 @@ class FreshmeatPlugin < Plugin title_width = 0 done = 0 doc.elements.each("*/channel/item") {|e| - desc = e.elements["description"].text - title = e.elements["title"].text + desc = e.elements["description"].text.ircify_html + title = e.elements["title"].text.ircify_html #title.gsub!(/\s+\(.*\)\s*$/, "") title.strip! title_width = title.length if title.length > title_width @@ -100,5 +134,5 @@ end plugin = FreshmeatPlugin.new plugin.map 'freshmeat search :limit *search', :action => 'search_freshmeat', :defaults => {:limit => 4}, :requirements => {:limit => /^\d+$/} -plugin.map 'freshmeat :limit', :defaults => {:limit => 4}, +plugin.map 'freshmeat :limit', :defaults => {:limit => 4}, :requirements => {:limit => /^\d+$/}