2005-07-22 02:14:48 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require "rss"
|
|
|
|
|
|
|
|
def error(exception)
|
|
|
|
mark = "=" * 20
|
|
|
|
mark = "#{mark} error #{mark}"
|
|
|
|
puts mark
|
|
|
|
puts exception.class
|
|
|
|
puts exception.message
|
|
|
|
puts exception.backtrace
|
|
|
|
puts mark
|
|
|
|
end
|
|
|
|
|
|
|
|
verbose = false
|
|
|
|
before_time = Time.now
|
|
|
|
|
|
|
|
ARGV.each do |fname|
|
|
|
|
if fname == '-v'
|
|
|
|
verbose = true
|
|
|
|
next
|
|
|
|
end
|
|
|
|
source = nil
|
|
|
|
File.open(fname) do |f|
|
|
|
|
source = f.read
|
|
|
|
end
|
2011-05-15 07:55:52 -04:00
|
|
|
|
2005-07-22 02:14:48 -04:00
|
|
|
rss = nil
|
|
|
|
read = false
|
|
|
|
begin
|
|
|
|
rss = RSS::Parser.parse(source)
|
2007-03-17 06:13:25 -04:00
|
|
|
puts "Re-read valid feed: #{fname}"
|
2005-07-22 02:14:48 -04:00
|
|
|
RSS::Parser.parse(rss.to_s)
|
|
|
|
read = true
|
|
|
|
rescue RSS::InvalidRSSError
|
|
|
|
error($!) if verbose
|
2007-03-17 06:13:25 -04:00
|
|
|
## do non validate parse for invalid feed
|
2005-07-22 02:14:48 -04:00
|
|
|
begin
|
|
|
|
rss = RSS::Parser.parse(source, false)
|
|
|
|
rescue RSS::Error
|
2007-03-17 06:13:25 -04:00
|
|
|
## invalid feed
|
2005-07-22 02:14:48 -04:00
|
|
|
error($!) if verbose
|
|
|
|
end
|
|
|
|
rescue RSS::Error
|
|
|
|
error($!) if verbose
|
|
|
|
end
|
2011-05-15 07:55:52 -04:00
|
|
|
|
2005-07-22 02:14:48 -04:00
|
|
|
if rss.nil?
|
2007-03-17 06:13:25 -04:00
|
|
|
puts "Invalid feed: #{fname}"
|
2005-07-22 02:14:48 -04:00
|
|
|
elsif !read
|
2007-03-17 06:13:25 -04:00
|
|
|
puts "Re-read invalid feed: #{fname}"
|
2005-07-22 02:14:48 -04:00
|
|
|
begin
|
|
|
|
RSS::Parser.parse(rss.to_s)
|
|
|
|
rescue RSS::Error
|
|
|
|
puts " Error occurred: #{fname}"
|
|
|
|
error($!) if verbose
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
processing_time = Time.now - before_time
|
|
|
|
|
|
|
|
puts "Used XML parser: #{RSS::Parser.default_parser}"
|
|
|
|
puts "Processing time: #{processing_time}s"
|