1 require 'rexml/document'
4 class FreshmeatPlugin < Plugin
6 def help(plugin, topic="")
7 "freshmeat search <string> [<max>=4] => search freshmeat for <string>, freshmeat [<max>=4] => return up to <max> freshmeat headlines"
10 if m.params && m.params =~ /^search\s+(.*)\s+(\d+)$/
13 search_freshmeat m, search, limit
14 elsif m.params && m.params =~ /^search\s+(.*)$/
16 search_freshmeat m, search
17 elsif m.params && m.params =~ /^(\d+)$/
25 def search_freshmeat(m, search, max=4)
28 xml = Utils.http_get("http://freshmeat.net/search-xml/?orderby=locate_projectname_full_DESC&q=#{URI.escape(search)}")
29 rescue URI::InvalidURIError, URI::BadURIError => e
30 m.reply "illegal search string #{search}"
34 m.reply "search for #{search} failed"
37 doc = Document.new xml
39 m.reply "search for #{search} failed"
47 doc.elements.each("*/match") {|e|
48 name = e.elements["projectname_short"].text
49 url = "http://freshmeat.net/projects/#{name}/"
50 desc = e.elements["desc_short"].text
51 title = e.elements["projectname_full"].text
52 #title_width = title.length if title.length > title_width
53 url_width = url.length if url.length > url_width
54 matches << [title, url, desc]
58 if matches.length == 0
59 m.reply "not found: #{search}"
65 desc.gsub!(/(.{#{max_width - 3 - url_width}}).*/, '\1..')
66 reply = sprintf("%s | %s", url.ljust(url_width), desc)
71 def freshmeat(m, max=4)
73 xml = Utils.http_get("http://images.feedstermedia.com/feedcache/ostg/freshmeat/fm-releases-global.xml")
75 m.reply "freshmeat news parse failed"
78 doc = Document.new xml
80 m.reply "freshmeat news parse failed"
87 doc.elements.each("*/channel/item") {|e|
88 desc = e.elements["description"].text
89 title = e.elements["title"].text
90 #title.gsub!(/\s+\(.*\)\s*$/, "")
92 title_width = title.length if title.length > title_width
93 matches << [title, desc]
100 #desc.gsub!(/(.{#{max_width - 3 - title_width}}).*/, '\1..')
101 #reply = sprintf("%#{title_width}s | %s", title, desc)
106 plugin = FreshmeatPlugin.new
107 plugin.register("freshmeat")