summaryrefslogtreecommitdiff
path: root/data/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-01-30 18:24:34 +0100
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-01-30 18:24:34 +0100
commit36f1f28e668919dfab75c8fc4d1020abad351bd1 (patch)
treef5c3e6cb0690eb5c925814debf009a470d2e0f08 /data/rbot
parentff5357cc9a5778a3cb8231bc01122bd0cd6f772d (diff)
rss plugin: try all RSS parsers
Some feeds fail when parsed by some parsers, but work correctly with others (e.g. http://www.blueman.com/community/rss fails with xmlparser but not with REXML). So try all of them and only abort if none works rather than failing because the default parser fails.
Diffstat (limited to 'data/rbot')
-rw-r--r--data/rbot/plugins/rss.rb39
1 files changed, 23 insertions, 16 deletions
diff --git a/data/rbot/plugins/rss.rb b/data/rbot/plugins/rss.rb
index 87f79ec5..981eb4f8 100644
--- a/data/rbot/plugins/rss.rb
+++ b/data/rbot/plugins/rss.rb
@@ -1134,25 +1134,32 @@ class RSSFeedsPlugin < Plugin
return nil unless feed.xml
feed.mutex.synchronize do
xml = feed.xml
- begin
- ## do validate parse
- rss = RSS::Parser.parse(xml)
- debug "parsed and validated #{feed}"
- rescue RSS::InvalidRSSError
- ## do non validate parse for invalid RSS 1.0
+ rss = nil
+ errors = []
+ RSS::AVAILABLE_PARSERS.each do |parser|
begin
- rss = RSS::Parser.parse(xml, false)
- debug "parsed but not validated #{feed}"
+ ## do validate parse
+ rss = RSS::Parser.parse(xml, true, true, parser)
+ debug "parsed and validated #{feed} with #{parser}"
+ break
+ rescue RSS::InvalidRSSError
+ begin
+ ## do non validate parse for invalid RSS 1.0
+ rss = RSS::Parser.parse(xml, false, true, parser)
+ debug "parsed but not validated #{feed} with #{parser}"
+ break
+ rescue RSS::Error => e
+ errors << [parser, e, "parsing rss stream failed, whoops =("]
+ end
rescue RSS::Error => e
- report_problem("parsing rss stream failed, whoops =(", e, m)
- return nil
+ errors << [parser, e, "parsing rss stream failed, oioi"]
+ rescue => e
+ errors << [parser, e, "processing error occured, sorry =("]
end
- rescue RSS::Error => e
- report_problem("parsing rss stream failed, oioi", e, m)
- return nil
- rescue => e
- report_problem("processing error occured, sorry =(", e, m)
- return nil
+ end
+ debug errors unless errors.empty?
+ if !rss
+ self.send(:report_problem, errors.last[2], errors.last[1], m)
end
items = []
if rss.nil?