summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/freshmeat.rb
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2005-07-27 15:59:13 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2005-07-27 15:59:13 +0000
commit21949774b91eaec6ecde4eaa8ad121e2c0a36b87 (patch)
tree41a7601e168018ac203bad7ca8d7f9f82515bc28 /data/rbot/plugins/freshmeat.rb
parent51cf09ec02d089bfdd80e5f728cfc92a234dc437 (diff)
rearrange repo for packaging
Diffstat (limited to 'data/rbot/plugins/freshmeat.rb')
-rw-r--r--data/rbot/plugins/freshmeat.rb98
1 files changed, 98 insertions, 0 deletions
diff --git a/data/rbot/plugins/freshmeat.rb b/data/rbot/plugins/freshmeat.rb
new file mode 100644
index 00000000..20fa7248
--- /dev/null
+++ b/data/rbot/plugins/freshmeat.rb
@@ -0,0 +1,98 @@
+require 'rexml/document'
+require 'uri/common'
+
+class FreshmeatPlugin < Plugin
+ include REXML
+ def help(plugin, topic="")
+ "freshmeat search [<max>=4] <string> => search freshmeat for <string>, freshmeat [<max>=4] => return up to <max> freshmeat headlines"
+ 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(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
+ unless xml
+ m.reply "search for #{search} failed"
+ return
+ end
+ doc = Document.new xml
+ unless doc
+ m.reply "search for #{search} failed"
+ return
+ end
+ matches = Array.new
+ max_width = 250
+ title_width = 0
+ url_width = 0
+ done = 0
+ doc.elements.each("*/match") {|e|
+ name = e.elements["projectname_short"].text
+ url = "http://freshmeat.net/projects/#{name}/"
+ desc = e.elements["desc_short"].text
+ title = e.elements["projectname_full"].text
+ #title_width = title.length if title.length > title_width
+ url_width = url.length if url.length > url_width
+ matches << [title, url, desc]
+ done += 1
+ break if done >= max
+ }
+ if matches.length == 0
+ m.reply "not found: #{search}"
+ end
+ matches.each {|mat|
+ title = mat[0]
+ url = mat[1]
+ desc = mat[2]
+ desc.gsub!(/(.{#{max_width - 3 - url_width}}).*/, '\1..')
+ reply = sprintf("%s | %s", url.ljust(url_width), desc)
+ m.reply reply
+ }
+ end
+
+ def freshmeat(m, params)
+ max = params[:limit].to_i
+ max = 8 if max > 8
+ xml = @bot.httputil.get(URI.parse("http://images.feedstermedia.com/feedcache/ostg/freshmeat/fm-releases-global.xml"))
+ unless xml
+ m.reply "freshmeat news parse failed"
+ return
+ end
+ doc = Document.new xml
+ unless doc
+ m.reply "freshmeat news parse failed"
+ return
+ end
+ matches = Array.new
+ max_width = 60
+ title_width = 0
+ done = 0
+ doc.elements.each("*/channel/item") {|e|
+ desc = e.elements["description"].text
+ title = e.elements["title"].text
+ #title.gsub!(/\s+\(.*\)\s*$/, "")
+ title.strip!
+ title_width = title.length if title.length > title_width
+ matches << [title, desc]
+ done += 1
+ break if done >= max
+ }
+ matches.each {|mat|
+ title = mat[0]
+ #desc = mat[1]
+ #desc.gsub!(/(.{#{max_width - 3 - title_width}}).*/, '\1..')
+ #reply = sprintf("%#{title_width}s | %s", title, desc)
+ m.reply title
+ }
+ end
+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},
+ :requirements => {:limit => /^\d+$/}