X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Ffreshmeat.rb;h=494cfb48b2374553d4f753e15548d3cc9d845a66;hb=7a128ab6457c9b79ed31a5562be98e1718bfaf80;hp=c8f529cbcf73c514899a0b5d8794ca7f1a695453;hpb=43ac960aa89e5a02291fe875627dac88ae7fda34;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/freshmeat.rb b/data/rbot/plugins/freshmeat.rb index c8f529cb..494cfb48 100644 --- a/data/rbot/plugins/freshmeat.rb +++ b/data/rbot/plugins/freshmeat.rb @@ -1,22 +1,50 @@ +#-- 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_cached(URI.parse("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 @@ -59,7 +87,7 @@ class FreshmeatPlugin < Plugin max = params[:limit].to_i max = 8 if max > 8 begin - xml = @bot.httputil.get(URI.parse("http://images.feedstermedia.com/feedcache/ostg/freshmeat/fm-releases-global.xml")) + xml = @bot.httputil.get('http://images.feedstermedia.com/feedcache/ostg/freshmeat/fm-releases-global.xml') unless xml m.reply "freshmeat news parse failed" return