Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement