|
@@ -4,27 +4,32 @@ module RSS
|
|
|
items = Cache.get( cache_key )
|
|
|
return items if items
|
|
|
|
|
|
- puts 'fetch rss...'
|
|
|
- response = Net::HTTP.get_response( URI.parse(url) )
|
|
|
- if response.code.to_s != '200'
|
|
|
- return
|
|
|
- end
|
|
|
- rss = SimpleRSS.parse response.body
|
|
|
- items = []
|
|
|
- fetched = 0
|
|
|
- rss.items.each { |item|
|
|
|
- record = {
|
|
|
- :id => item.id,
|
|
|
- :title => item.title,
|
|
|
- :summary => item.summary,
|
|
|
- :link => item.link,
|
|
|
- :published => item.published
|
|
|
+ begin
|
|
|
+ puts 'fetch rss...'
|
|
|
+ response = Net::HTTP.get_response( URI.parse(url) )
|
|
|
+ if response.code.to_s != '200'
|
|
|
+ return
|
|
|
+ end
|
|
|
+ rss = SimpleRSS.parse response.body
|
|
|
+ items = []
|
|
|
+ fetched = 0
|
|
|
+ rss.items.each { |item|
|
|
|
+ record = {
|
|
|
+ :id => item.id,
|
|
|
+ :title => item.title,
|
|
|
+ :summary => item.summary,
|
|
|
+ :link => item.link,
|
|
|
+ :published => item.published
|
|
|
+ }
|
|
|
+ items.push record
|
|
|
+ fetched += 1
|
|
|
+ break item if fetched == limit.to_i
|
|
|
}
|
|
|
- items.push record
|
|
|
- fetched += 1
|
|
|
- break item if fetched == limit.to_i
|
|
|
- }
|
|
|
- Cache.write( cache_key, items, :expires_in => 4.hours )
|
|
|
+ Cache.write( cache_key, items, :expires_in => 4.hours )
|
|
|
+ rescue Exception => e
|
|
|
+ puts "can't fetch #{url}"
|
|
|
+ puts e.inspect
|
|
|
+ end
|
|
|
|
|
|
return items
|
|
|
end
|