Prev | Current Page 302 | Next

David Berube

"Practical Reporting with Ruby and Rails"


execute "ALTER TABLE cached_feeds
CHANGE COLUMN feed_data feed_data MEDIUMTEXT;"
end
end
output_format = 'rss'
per_page = 100
query = ARGV[0]
query_encoded = URI.encode(query) # URI.encode will escape values like "&"
# that would mess up our URL.
feed_url = "http://news.google.com/news" <<
"?hl=en&ned=us&ie=UTF-8" <<
"&num=" << per_page <<
"&output=" << output_format <<
"&q=" << query_encoded
# Set up our cache:
FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
# Create our feed object:
feed=FeedTools::Feed.open(feed_url)
if !feed.live?
puts "feed is cached..."
puts "last retrieved: #{ feed.last_retrieved }"
puts "expires: #{ feed.last_retrieved + feed.time_to_live }"
CHAPTER 11 n TRACKING THE NEWS WITH GOOGLE NEWS 219
else
feed.items.each do |feed_story|
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:
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
mieszkania sosnowiec Paula Atherton Na wylot Danny 2 1