summaryrefslogtreecommitdiff
path: root/sample/rss
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-27 08:41:32 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-27 08:41:32 +0000
commitb325d73c13d683352e2917b4c00bb1593982c3c9 (patch)
tree21ba5921f6f8f78434f38ed0aa57ceb27f3bb3f1 /sample/rss
parent5e5fe659fab94c09a322992149c2ff794fe18451 (diff)
* sample/rss/list_description.rb: untabified.
* sample/rss/rss_recent.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample/rss')
-rw-r--r--sample/rss/list_description.rb114
-rw-r--r--sample/rss/rss_recent.rb114
2 files changed, 114 insertions, 114 deletions
diff --git a/sample/rss/list_description.rb b/sample/rss/list_description.rb
index e0b59ea..ac1db09 100644
--- a/sample/rss/list_description.rb
+++ b/sample/rss/list_description.rb
@@ -2,12 +2,12 @@
require "nkf"
class String
- # From tdiary.rb
- def shorten( len = 120 )
- lines = NKF::nkf( "-e -m0 -f#{len}", self.gsub( /\n/, ' ' ) ).split( /\n/ )
- lines[0].concat( '...' ) if lines[0] and lines[1]
- lines[0]
- end
+ # From tdiary.rb
+ def shorten( len = 120 )
+ lines = NKF::nkf( "-e -m0 -f#{len}", self.gsub( /\n/, ' ' ) ).split( /\n/ )
+ lines[0].concat( '...' ) if lines[0] and lines[1]
+ lines[0]
+ end
end
require "rss/1.0"
@@ -18,66 +18,66 @@ channels = {}
verbose = false
def error(exception)
- mark = "=" * 20
- mark = "#{mark} error #{mark}"
- puts mark
- puts exception.class
- puts exception.message
- puts exception.backtrace
- puts mark
+ mark = "=" * 20
+ mark = "#{mark} error #{mark}"
+ puts mark
+ puts exception.class
+ puts exception.message
+ puts exception.backtrace
+ puts mark
end
before_time = Time.now
ARGV.each do |fname|
- if fname == '-v'
- verbose = true
- next
- end
- rss = nil
- f = File.new(fname).read
- begin
- ## do validate parse
- rss = RSS::Parser.parse(f)
- rescue RSS::InvalidRSSError
- error($!) if verbose
- ## do non validate parse for invalid RSS 1.0
- begin
- rss = RSS::Parser.parse(f, false)
- rescue RSS::Error
- ## invalid RSS.
- error($!) if verbose
- end
- rescue RSS::Error
- error($!) if verbose
- end
- if rss.nil?
- puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
- else
- begin
- rss.output_encoding = "euc-jp"
- rescue RSS::UnknownConversionMethodError
- error($!) if verbose
- end
- rss.channel.title ||= "Unknown"
- rss.items.each do |item|
- item.title ||= "Unknown"
- channels[rss.channel.title] ||= []
- channels[rss.channel.title] << item if item.description
- end
- end
+ if fname == '-v'
+ verbose = true
+ next
+ end
+ rss = nil
+ f = File.new(fname).read
+ begin
+ ## do validate parse
+ rss = RSS::Parser.parse(f)
+ rescue RSS::InvalidRSSError
+ error($!) if verbose
+ ## do non validate parse for invalid RSS 1.0
+ begin
+ rss = RSS::Parser.parse(f, false)
+ rescue RSS::Error
+ ## invalid RSS.
+ error($!) if verbose
+ end
+ rescue RSS::Error
+ error($!) if verbose
+ end
+ if rss.nil?
+ puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
+ else
+ begin
+ rss.output_encoding = "euc-jp"
+ rescue RSS::UnknownConversionMethodError
+ error($!) if verbose
+ end
+ rss.channel.title ||= "Unknown"
+ rss.items.each do |item|
+ item.title ||= "Unknown"
+ channels[rss.channel.title] ||= []
+ channels[rss.channel.title] << item if item.description
+ end
+ end
end
processing_time = Time.now - before_time
channels.sort do |x, y|
- x[0] <=> y[0]
+ x[0] <=> y[0]
end[0..20].each do |title, items|
- puts "Channel: #{title}" unless items.empty?
- items.sort do |x, y|
- x.title <=> y.title
- end[0..10].each do |item|
- puts " Item: #{item.title.shorten(50)}"
- puts " Description: #{item.description.shorten(50)}"
- end
+ puts "Channel: #{title}" unless items.empty?
+ items.sort do |x, y|
+ x.title <=> y.title
+ end[0..10].each do |item|
+ puts " Item: #{item.title.shorten(50)}"
+ puts " Description: #{item.description.shorten(50)}"
+ end
end
puts "Used XML parser: #{RSS::Parser.default_parser}"
diff --git a/sample/rss/rss_recent.rb b/sample/rss/rss_recent.rb
index 8e40151..70776c1 100644
--- a/sample/rss/rss_recent.rb
+++ b/sample/rss/rss_recent.rb
@@ -2,12 +2,12 @@
require "nkf"
class String
- # From tdiary.rb
- def shorten( len = 120 )
- lines = NKF::nkf( "-e -m0 -f#{len}", self.gsub( /\n/, ' ' ) ).split( /\n/ )
- lines[0].concat( '...' ) if lines[0] and lines[1]
- lines[0]
- end
+ # From tdiary.rb
+ def shorten( len = 120 )
+ lines = NKF::nkf( "-e -m0 -f#{len}", self.gsub( /\n/, ' ' ) ).split( /\n/ )
+ lines[0].concat( '...' ) if lines[0] and lines[1]
+ lines[0]
+ end
end
require "rss/1.0"
@@ -18,65 +18,65 @@ items = []
verbose = false
def error(exception)
- mark = "=" * 20
- mark = "#{mark} error #{mark}"
- puts mark
- puts exception.class
- puts exception.message
- puts exception.backtrace
- puts mark
+ mark = "=" * 20
+ mark = "#{mark} error #{mark}"
+ puts mark
+ puts exception.class
+ puts exception.message
+ puts exception.backtrace
+ puts mark
end
before_time = Time.now
ARGV.each do |fname|
- if fname == '-v'
- verbose = true
- next
- end
- rss = nil
- f = File.new(fname).read
- begin
- ## do validate parse
- rss = RSS::Parser.parse(f)
- rescue RSS::InvalidRSSError
- error($!) if verbose
- ## do non validate parse for invalid RSS 1.0
- begin
- rss = RSS::Parser.parse(f, false)
- rescue RSS::Error
- ## invalid RSS.
- error($!) if verbose
- end
- rescue RSS::Error
- error($!) if verbose
- end
- if rss.nil?
- puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
- else
- begin
- rss.output_encoding = "euc-jp"
- rescue RSS::UnknownConversionMethodError
- error($!) if verbose
- end
- rss.items.each do |item|
- if item.respond_to?(:pubDate) and item.pubDate
- class << item
- alias_method(:dc_date, :pubDate)
- end
- end
- if item.respond_to?(:dc_date) and item.dc_date
- items << [rss.channel, item]
- end
- end
- end
+ if fname == '-v'
+ verbose = true
+ next
+ end
+ rss = nil
+ f = File.new(fname).read
+ begin
+ ## do validate parse
+ rss = RSS::Parser.parse(f)
+ rescue RSS::InvalidRSSError
+ error($!) if verbose
+ ## do non validate parse for invalid RSS 1.0
+ begin
+ rss = RSS::Parser.parse(f, false)
+ rescue RSS::Error
+ ## invalid RSS.
+ error($!) if verbose
+ end
+ rescue RSS::Error
+ error($!) if verbose
+ end
+ if rss.nil?
+ puts "#{fname} does not include RSS 1.0 or 0.9x/2.0"
+ else
+ begin
+ rss.output_encoding = "euc-jp"
+ rescue RSS::UnknownConversionMethodError
+ error($!) if verbose
+ end
+ rss.items.each do |item|
+ if item.respond_to?(:pubDate) and item.pubDate
+ class << item
+ alias_method(:dc_date, :pubDate)
+ end
+ end
+ if item.respond_to?(:dc_date) and item.dc_date
+ items << [rss.channel, item]
+ end
+ end
+ end
end
processing_time = Time.now - before_time
items.sort do |x, y|
- y[1].dc_date <=> x[1].dc_date
+ y[1].dc_date <=> x[1].dc_date
end[0..20].each do |channel, item|
- puts "#{item.dc_date.localtime.iso8601}: " <<
- "#{channel.title}: #{item.title}"
- puts " Description: #{item.description.shorten(50)}" if item.description
+ puts "#{item.dc_date.localtime.iso8601}: " <<
+ "#{channel.title}: #{item.title}"
+ puts " Description: #{item.description.shorten(50)}" if item.description
end
puts "Used XML parser: #{RSS::Parser.default_parser}"