a ruby script to retrieve idea plugins

Hi,

I have a ruby script to retrieve idea plugin information from www.intellij.org and generate a html page which lists all plugins sorted by modification date.

Requirements:
ruby (http://www.ruby-lang.org/en)
windows distribution can be downloaded here
(http://www.dm4lab.to/~usa/ruby/index_en.html)
REXML (http://www.germane-software.com/software/rexml/)

Here is the source code:
##################################################

require 'net/http'

h = Net::HTTP.new('www.intellij.org', 80)
resp, data = h.get('/twiki/bin/view/Main/IntelliJPluginPackageXML?skin=plain', nil )
startIdx = data.index("<!-- xml:begin -->")
endIdx = data.index("<!-- xml:end -->")
xmlstr = data[startIdx,endIdx - startIdx]
#print xmlstr + "\n"

require "rexml/document"
doc = REXML::Document.new xmlstr

MONTH_TABLE = {
"JAN"=>"01", "FEB"=>"02", "MAR"=>"03",
"APR"=>"04", "MAY"=>"05", "JUN"=>"06",
"JUL"=>"07", "AUG"=>"08", "SEP"=>"09",
"OCT"=>"10", "NOV"=>"11", "DEC"=>"12"}

elems = Hash.new

doc.elements.each("//idea-plugin") do |elem|

  1. lastModStr = "13 Aug 2003 - 15:05"

lastModStr = elem.elements["lastModified"].text
dateStr = lastModStr[9,2] + MONTH_TABLE[lastModStr[3,3].upcase] \
+ lastModStr[0,2] + lastModStr[14,2] + lastModStr[17,2]
elems[dateStr] = elem
end

keys = elems.keys
keys.sort!
keys.reverse!

$stdout = File.new("idea-plugins.html", "w")
print "Generated index for IDEA plugins\n" keys.each do |key| elem = elems[key] docUrlElem = elem.elements["docUrl"] name = elem.elements["name"].text name = docUrlElem.text[docUrlElem.text.rindex("/")..-1] if name.nil? and docUrlElem and docUrlElem.text print "" print name if name print " " verElem = elem.elements["version"] print verElem.text if verElem and verElem.text print "\tModified at "+elem.elements["lastModified"].text print "\n
\n" descElem = elem.elements["description"] print descElem.text+"
]]>
\n" if descElem and descElem.text
binUrlElem = elem.elements["binUrl"]
print "\n<a href="binUrlElem.text">"binUrlElem.text"
]]>
\n" if binUrlElem and binUrlElem.text
srcUrlElem = elem.elements["srcUrl"]
print "\n<a href="srcUrlElem.text">"srcUrlElem.text"
]]>
\n" if srcUrlElem and srcUrlElem.text
print "\n<a href="docUrlElem.text">"docUrlElem.text"
\n" if docUrlElem and docUrlElem.text print "\n


\n" end print "

1 comment
Comment actions Permalink

Sorry for the vapid post, but i have to say, ruby is pretty cool.

0

Please sign in to leave a comment.