Created
August 5, 2010 00:19
-
-
Save pfleidi/509020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'rexml/document' | |
require 'trollop' | |
@options = Trollop::options do | |
version "parseitems.rb 0.1 (c) 2010 Sven Pfleiderer" | |
banner <<-EOS | |
This is a simple, script which takes an xml file with items and generates a wiki table with the given content | |
Usage: | |
parseitems.rb -i <filename> | |
EOS | |
opt :input, "Input file", :type => String | |
end | |
if (@options[:input].nil? or !File.exist?(@options[:input])) | |
Trollop::die "must specify an existant input file" | |
end | |
def parse_items(document) | |
items = Array.new | |
REXML::XPath.each(document, "//item[@id]") do |fe| | |
items << fe | |
end | |
items | |
end | |
def read_items | |
begin | |
item_file = File.read(@options[:input]) | |
item_document = REXML::Document.new(item_file) | |
items = parse_items(item_document) | |
rescue NoMethodError | |
puts "File #{@options[:input]} could not be parsed!" | |
rescue | |
puts "File #{@options[:input]} not found!" | |
end | |
return items if items | |
end | |
# |[[url|id]]|owner|desc|usage|deadline|public| | |
read_items.each do |item| | |
att = item.attributes | |
puts "|[[http://xt3.fourtyone.org/~xt3/shack/small_#{att['id']}.JPG|#{att['id']}]]|#{att['owner'] or "n/a"}|#{att['desc'] or "n/a"}|#{att['usage'] or "n/a"}|#{att['deadline'] or "n/a"}|#{att['public'] or "n/a"}|" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment