Advertisement
Guest User

Untitled

a guest
Dec 28th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'rubygems'
  4. require 'rexml/document'
  5. require 'trollop'
  6.  
  7. @options = Trollop::options do
  8. version "parseitems.rb 0.1 (c) 2010 Sven Pfleiderer"
  9. banner <<-EOS
  10. This is a simple, script which takes an xml file with items and generates a wiki table with the given content
  11.  
  12. Usage:
  13.  
  14. parseitems.rb -i <filename>
  15. EOS
  16. opt :input, "Input file", :type => String
  17. end
  18.  
  19. if (@options[:input].nil? or !File.exist?(@options[:input]))
  20. Trollop::die "must specify an existant input file"
  21. end
  22.  
  23. def parse_items(document)
  24. items = Array.new
  25. REXML::XPath.each(document, "//item[@id]") do |fe|
  26. items << fe
  27. end
  28. items
  29. end
  30.  
  31. def read_items
  32. begin
  33. item_file = File.read(@options[:input])
  34. item_document = REXML::Document.new(item_file)
  35. items = parse_items(item_document)
  36. rescue NoMethodError
  37. puts "File #{@options[:input]} could not be parsed!"
  38. rescue
  39. puts "File #{@options[:input]} not found!"
  40. end
  41. return items if items
  42. end
  43.  
  44. # |[[url|id]]|owner|desc|usage|deadline|public|
  45. read_items.each do |item|
  46. att = item.attributes
  47. 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"}|"
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement