Hi,
I have downloaded a piece of code in ruby that will get quotes from
Yahoo Finance. The code is pasted below:
require ‘yahoofinance’
require ‘open-uri’
require ‘rexml/document’
require ‘pp’
require ‘net/http.rb’
Set the type of quote we want to retrieve.
Available type are:
- YahooFinanace::StandardQuote
- YahooFinanace::ExtendedQuote
- YahooFinanace::RealTimeQuote
quote_type = YahooFinance::StandardQuote
Set the symbols for which we want to retrieve quotes.
You can include more than one symbol by separating
them with a ‘,’ (comma).
quote_symbols = “500570.BO”
#quote_symbols = “YHOO”
Get the quotes from Yahoo! Finance. The get_quotes method call
returns a Hash containing one quote object of type “quote_type” for
each symbol in “quote_symbols”. If a block is given, it will be
called with the quote object (as in the example below).
YahooFinance::get_quotes( quote_type, quote_symbols ) do |qt|
puts “QUOTING: #{qt.symbol}”
puts qt.to_s
end
You can get the same effect using the quote specific method.
quotes = YahooFinance::get_standard_quotes( quote_symbols )
quotes.each do |symbol, qt|
puts “QUOTING: #{symbol}”
puts qt.to_s
end
The above piece of code works fine when i use this directly in a .rb
file like this:
ruby testyahoo.rb
I get the stock quotes correctly.
But i have problems if i put exactly the same code between html tags
call it this way:
eruby testyahoo.rhtml
Code for testyahoo.rhtml file is pasted below:
#!C:/appdev/ruby/bin/eruby.exe
eruby testeruby test
<%
require ‘yahoofinance’
require ‘open-uri’
require ‘rexml/document’
require ‘pp’
require ‘net/http.rb’
Set the type of quote we want to retrieve.
Available type are:
- YahooFinanace::StandardQuote
- YahooFinanace::ExtendedQuote
- YahooFinanace::RealTimeQuote
quote_type = YahooFinance::StandardQuote
Set the symbols for which we want to retrieve quotes.
You can include more than one symbol by separating
them with a ‘,’ (comma).
quote_symbols = “500570.BO”
#quote_symbols = “YHOO”
Get the quotes from Yahoo! Finance. The get_quotes method call
returns a Hash containing one quote object of type “quote_type” for
each symbol in “quote_symbols”. If a block is given, it will be
called with the quote object (as in the example below).
YahooFinance::get_quotes( quote_type, quote_symbols ) do |qt|
puts “QUOTING: #{qt.symbol}”
puts qt.to_s
end
You can get the same effect using the quote specific method.
quotes = YahooFinance::get_standard_quotes( quote_symbols )
quotes.each do |symbol, qt|
puts “QUOTING: #{symbol}”
puts qt.to_s
end
%>
I have attached a screen capture of the errors when the .rhtml file is
executed.
I am not able to figure out if my eruby installation is wrong or if my
path settings are incorrect. I tried eruby with other pieces of code
that dont need http.rb and these pieces of code work absolutely fine.
I have ruby, rubygems, eruby, mysql and apache running on a windows
vista system.
Any inputs would help.
Thanks & Regards
Aditya