Quantcast
Viewing all articles
Browse latest Browse all 2

Answer by middleinitial for How to fetch RSS feeds from yahoo finance page and show in my Rails app?

Ryan Bates has a railscast on one way to handle the problem:http://railscasts.com/episodes/168-feed-parsing

You should definitely have a model for this data. The goal should be to get the model handling the fetching and parsing of data.

If you aren't interested in saving information to your own database(as is shown in the railscast episode), beware you will incur a bit of a performance penalty for making a request to yahoo on every page load.

Here's a simple example of a method you could add to your model.

def self.lookup_stock_titles(stock_name)  titles = Array.new  Feedzirra::Feed.fetch_and_parse("http://feeds.finance.yahoo.com/rss/2.0/headline?s=#{stock_name}&region=US&lang=en-US").entries.each do |entry|     titles << entry.title  end  return titlesend

This would give you an array of titles from the rss feed which you could integrate into a controller or view however you like.

<% ModelName.lookup_stock_titles("ABC").each do |title| %><h2><%= title %></h2><% end %>

Also be sure that yahoo allows you to use their data the way you want, saving it to a database, number of requests per hour, what kind of credit do you need to give to them, etc.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>