Prev | Current Page 310 | Next

David Berube

"Practical Reporting with Ruby and Rails"


Now that you have a database connection, a structure, and a model, you need to construct
a Google News URL and download the data:
output_format = 'rss'
per_page = 100
query = ARGV[0]
query_encoded = URI.encode(query)
feed_url = "http://news.google.com/news" <<
"?hl=en&ned=us&ie=UTF-8" <<
"&num=" << per_page <<
"&output=" << output_format <<
"&q=" << query_encoded
CHAPTER 11 n TRACKING THE NEWS WITH GOOGLE NEWS 224
FeedTools.configurations[:feed_cache] = "FeedTools::DatabaseFeedCache"
feed=FeedTools::Feed.open(feed_url)
The URL was initially constructed by making a sample search on Google News, noting
the RSS URL it generated, and creating code that generates the URL. You can follow a
similar technique to create URL-generation code for other services, such as Google Blog
Search, for example.
Two static variables, output_format and per_page, are used to create the URL. You can
vary these as desired. Of course, you could have hard-coded them into the URL, but separating
them makes them a bit easier to change.


Pages:
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
Magma Marie kreskowka Madness wlatcy moch