1 require 'rexml/document'
4 class FreshmeatPlugin < Plugin
6 def help(plugin, topic="")
7 "freshmeat search [<max>=4] <string> => search freshmeat for <string>, freshmeat [<max>=4] => return up to <max> freshmeat headlines"
10 def search_freshmeat(m, params)
11 max = params[:limit].to_i
12 search = params[:search].to_s
15 xml = @bot.httputil.get(URI.parse("http://freshmeat.net/search-xml/?orderby=locate_projectname_full_DESC&q=#{URI.escape(search)}"))
16 rescue URI::InvalidURIError, URI::BadURIError => e
17 m.reply "illegal search string #{search}"
21 m.reply "search for #{search} failed"
24 doc = Document.new xml
26 m.reply "search for #{search} failed"
34 doc.elements.each("*/match") {|e|
35 name = e.elements["projectname_short"].text
36 url = "http://freshmeat.net/projects/#{name}/"
37 desc = e.elements["desc_short"].text
38 title = e.elements["projectname_full"].text
39 #title_width = title.length if title.length > title_width
40 url_width = url.length if url.length > url_width
41 matches << [title, url, desc]
45 if matches.length == 0
46 m.reply "not found: #{search}"
52 desc.gsub!(/(.{#{max_width - 3 - url_width}}).*/, '\1..')
53 reply = sprintf("%s | %s", url.ljust(url_width), desc)
58 def freshmeat(m, params)
59 max = params[:limit].to_i
61 xml = @bot.httputil.get(URI.parse("http://images.feedstermedia.com/feedcache/ostg/freshmeat/fm-releases-global.xml"))
63 m.reply "freshmeat news parse failed"
66 doc = Document.new xml
68 m.reply "freshmeat news parse failed"
75 doc.elements.each("*/channel/item") {|e|
76 desc = e.elements["description"].text
77 title = e.elements["title"].text
78 #title.gsub!(/\s+\(.*\)\s*$/, "")
80 title_width = title.length if title.length > title_width
81 matches << [title, desc]
88 #desc.gsub!(/(.{#{max_width - 3 - title_width}}).*/, '\1..')
89 #reply = sprintf("%#{title_width}s | %s", title, desc)
94 plugin = FreshmeatPlugin.new
95 plugin.map 'freshmeat search :limit *search', :action => 'search_freshmeat',
96 :defaults => {:limit => 4}, :requirements => {:limit => /^\d+$/}
97 plugin.map 'freshmeat :limit', :defaults => {:limit => 4},
98 :requirements => {:limit => /^\d+$/}