Prev | Current Page 312 | Next

David Berube

"Practical Reporting with Ruby and Rails"

If you??™re inclined to write a custom FeedTools cache class??”
one that stores information in, say, a memcached server??”you can pass in a different
class name. Note that it??™s passed in as a string, not as a class constant or a symbol.
Then you open the feed using the FeedTools::Feed.open method. This method is format-
agnostic; it can be RSS, Atom, or CDF. Also, you don??™t need to use a separate method
to download the URL and then pass it to FeedTools, because FeedTools downloads the
feed and parses it in one step.
Finally, you add the stories to your MySQL database:
if !feed.live?
puts "feed is cached..."
puts "last retrieved: #{ feed.last_retrieved }"
puts "expires: #{ feed.last_retrieved + feed.time_to_live }"
else
feed.items.each do |feed_story|
CHAPTER 11 n TRACKING THE NEWS WITH GOOGLE NEWS 225
if not (Stories.find_by_title(feed_story.title) or
Stories.find_by_url(feed_story.link) or
Stories.find_by_guid(feed_story.guid))
puts "processing story '#{feed_story.title}' - new"
Stories.new do |new_story|
new_story.


Pages:
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
pustaki szklane House Extension Kąty Rybackie noclegi kasyno Kołobrzeg