yahoofinance 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +19 -8
- data/README +2 -3
- data/lib/yahoofinance.rb +65 -27
- metadata +3 -3
data/ChangeLog
CHANGED
@@ -1,30 +1,41 @@
|
|
1
|
-
|
1
|
+
2007-02-14 Nicholas Rahn <nick@transparentech.com>
|
2
|
+
* RELEASE 1.2.1
|
3
|
+
* lib/yahoofinance.rb: Change historical data parsing due to Yahoo! Finance format change. Don't catch exceptions in YahooFinance.get.
|
4
|
+
|
5
|
+
2006-11-12 Nicholas Rahn <nick@transparentech.com>
|
6
|
+
* lib/yahoofinance.rb: Improve (again) the exception handling for timeouts. Catch an 'Exception' rather than default which seems to miss the Timeout::Error.
|
7
|
+
|
8
|
+
2006-08-24 Nicholas Rahn <nick@transparentech.com>
|
9
|
+
* lib/yahoofinance.rb: add valid?() method.
|
10
|
+
|
11
|
+
2006-08-01 Nicholas Rahn <nick@transparentech.com>
|
12
|
+
* RELEASE 1.2.0
|
2
13
|
* lib/yahoofinance.rb: Internal cleanups and optimizations so we don't return or create big arrays if not necessary in the historical quote API.
|
3
14
|
|
4
|
-
2006-07-31 Nicholas Rahn <nick@
|
15
|
+
2006-07-31 Nicholas Rahn <nick@transparentech.com>
|
5
16
|
* Reorganize directory layout for gem.
|
6
17
|
* Rakefile: New rakefile for building a gem.
|
7
18
|
* lib/yahoofinance.rb: Add command line usage for historical quotes.
|
8
19
|
|
9
|
-
2006-05-04 Nicholas Rahn <nick@
|
20
|
+
2006-05-04 Nicholas Rahn <nick@transparentech.com>
|
10
21
|
* yahoofinance.rb: Re-organize the method names for historical quotes. Upgrade the downloading of historical data so that "international" market data that are available only in 200 data point chunks are completely downloaded (in multiple chunks).
|
11
22
|
|
12
|
-
2006-03-13 Nicholas Rahn <nick@
|
23
|
+
2006-03-13 Nicholas Rahn <nick@transparentech.com>
|
13
24
|
* yahoofinance.rb: Play around with timeouts in an attempt to find why requests will sometimes hang. Added a bit of error checking to get method. Probably can remove extra stuff later.
|
14
25
|
|
15
|
-
2006-01-01 Nicholas Rahn <nick@
|
26
|
+
2006-01-01 Nicholas Rahn <nick@transparentech.com>
|
16
27
|
* yahoofinance.rb: Start work on historical quote data retrieval. Mostly for use in Grism (www.grism.org).
|
17
28
|
|
18
|
-
2005-09-05 Nicholas Rahn <nick@
|
29
|
+
2005-09-05 Nicholas Rahn <nick@transparentech.com>
|
19
30
|
|
20
31
|
* yahoofinance.rb: add proper value conversion methods to some
|
21
32
|
extended quote variables.
|
22
33
|
|
23
|
-
2005-08-31 Nicholas Rahn <nick@
|
34
|
+
2005-08-31 Nicholas Rahn <nick@transparentech.com>
|
24
35
|
|
25
36
|
* yahoofinance.rb: Allow passing arrays of symbols as well as
|
26
37
|
comma delimited strings.
|
27
38
|
|
28
|
-
2005-08-30 Nicholas Rahn <nick@
|
39
|
+
2005-08-30 Nicholas Rahn <nick@transparentech.com>
|
29
40
|
|
30
41
|
* Release 1.0.0
|
data/README
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
YahooFinance ruby module
|
2
2
|
|
3
|
-
Homepage: http://www.
|
3
|
+
Homepage: http://www.transparentech.com/projects/yahoofinance
|
4
4
|
|
5
5
|
Ruby module for getting stock quote information from the
|
6
6
|
finance.yahoo.com website.
|
@@ -11,5 +11,4 @@ run from the command-line as a script.
|
|
11
11
|
|
12
12
|
Please see the homepage for more details.
|
13
13
|
|
14
|
-
Please send any comments or bug reports to "nick lives-here
|
15
|
-
pixel-grouping com".
|
14
|
+
Please send any comments or bug reports to "nick lives-here transparentech pixel-grouping com".
|
data/lib/yahoofinance.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
#
|
3
3
|
# YahooFinance ruby module.
|
4
|
-
# Homepage: http://www.
|
4
|
+
# Homepage: http://www.transparentech.com/projects/yahoofinance
|
5
5
|
#
|
6
6
|
# Ruby module for getting stock quote information from the
|
7
7
|
# finance.yahoo.com website.
|
@@ -10,7 +10,7 @@
|
|
10
10
|
# run from the command-line as a script.
|
11
11
|
#
|
12
12
|
#
|
13
|
-
# Copyright (c) 2006 Nicholas Rahn <nick at
|
13
|
+
# Copyright (c) 2006 Nicholas Rahn <nick at transparentech.com>
|
14
14
|
#
|
15
15
|
# This software may be freely redistributed under the terms of the GNU
|
16
16
|
# public license version 2.
|
@@ -32,7 +32,8 @@ require 'ostruct'
|
|
32
32
|
# randomly, but since upgrading to ruby 1.8.4, I haven't had many
|
33
33
|
# hangs. I also tend to think that Yahoo has improved the reliability
|
34
34
|
# of this service a bit. My guess is that most of the hangs were due
|
35
|
-
# to dropped requests.
|
35
|
+
# to dropped requests. Also, catching the correct Exception in the
|
36
|
+
# #get method, I think, fixed most of the remaining problems.
|
36
37
|
#
|
37
38
|
#require 'timeout'
|
38
39
|
|
@@ -153,28 +154,50 @@ module YahooFinance
|
|
153
154
|
|
154
155
|
DEFAULT_READ_TIMEOUT = 5
|
155
156
|
|
157
|
+
#
|
158
|
+
# Return a string containing the results retrieved from
|
159
|
+
# YahooFinance. If there was an error during the execution of this
|
160
|
+
# method, the string "" is returned. In practice, this means that
|
161
|
+
# no *Quote objects will be created (empty hashes will be returned
|
162
|
+
# from get_*_quotes methods).
|
163
|
+
#
|
156
164
|
def YahooFinance.get( symbols, format, timeout=DEFAULT_READ_TIMEOUT )
|
157
165
|
return "" if symbols == nil
|
158
166
|
symbols = symbols.join( "," ) if symbols.class == Array
|
159
167
|
symbols.strip!
|
160
168
|
return "" if symbols == ""
|
161
169
|
|
162
|
-
|
163
|
-
|
164
|
-
|
170
|
+
# Catch any exceptions that might occur here. Possible exceptions
|
171
|
+
# are the read_timeout and...
|
172
|
+
#
|
165
173
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
174
|
+
#
|
175
|
+
# Don't catch any exceptions! Just let them be thrown.
|
176
|
+
#
|
177
|
+
# begin
|
178
|
+
Net::HTTP.start( "finance.yahoo.com", 80 ) { |http|
|
179
|
+
http.read_timeout = timeout
|
171
180
|
response = nil
|
172
|
-
end
|
173
181
|
|
174
|
-
|
182
|
+
# begin
|
183
|
+
# Timeout.timeout( 1 ) {
|
184
|
+
response = http.get( "/d/quotes.csv?s=#{symbols}&f=#{format}&e=.csv" )
|
185
|
+
# }
|
186
|
+
# rescue Exception => ex
|
187
|
+
# puts "inner timeout got: #{ex.inspect}"
|
188
|
+
# response = nil
|
189
|
+
# end
|
190
|
+
|
191
|
+
return "" if !response
|
192
|
+
|
193
|
+
response.body.chomp
|
194
|
+
}
|
195
|
+
# rescue Exception => ex
|
196
|
+
# This can often be a Timeout::Error.
|
197
|
+
# puts "YahooFinance::get - #{ex.inspect}"
|
198
|
+
# return ""
|
199
|
+
# end
|
175
200
|
|
176
|
-
response.body.chomp
|
177
|
-
}
|
178
201
|
end
|
179
202
|
|
180
203
|
def YahooFinance.get_quotes( quote_class, symbols, &block )
|
@@ -250,6 +273,12 @@ module YahooFinance
|
|
250
273
|
parse( CSV.parse_line( csv ) )
|
251
274
|
end
|
252
275
|
|
276
|
+
def valid?()
|
277
|
+
# Not sure this is the best way to do this, but OK for now.
|
278
|
+
return self.name != self.symbol if self.name
|
279
|
+
false
|
280
|
+
end
|
281
|
+
|
253
282
|
def get_info()
|
254
283
|
"#{symbol} : #{name}"
|
255
284
|
end
|
@@ -342,18 +371,27 @@ module YahooFinance
|
|
342
371
|
|
343
372
|
@@date_re = /([0-9]{1,2})-([A-Za-z]+)-([0-9]{1,2})/
|
344
373
|
@@months = %w( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec )
|
374
|
+
|
375
|
+
#
|
376
|
+
# This method is obsolete since the Yahoo format change. However,
|
377
|
+
# I am leaving it here for API stability.
|
378
|
+
#
|
345
379
|
def HistoricalQuote.parse_date( date )
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
380
|
+
# Yahoo changed the format of the date column. It is now in the
|
381
|
+
# same format as this method returned, so this method just
|
382
|
+
# returns the same date.
|
383
|
+
return date
|
384
|
+
# md = @@date_re.match( date )
|
385
|
+
# if md
|
386
|
+
# if md[3].to_i > 30
|
387
|
+
# year = "19#{md[3]}"
|
388
|
+
# else
|
389
|
+
# year = "20#{md[3]}"
|
390
|
+
# end
|
391
|
+
# return "#{year}-%02d-%02d" % [(@@months.index(md[2]) + 1), md[1].to_i]
|
392
|
+
# else
|
393
|
+
# return date
|
394
|
+
# end
|
357
395
|
end
|
358
396
|
|
359
397
|
def HistoricalQuote.parse_date_to_Date( date )
|
@@ -392,7 +430,7 @@ module YahooFinance
|
|
392
430
|
|
393
431
|
# If we don't get the first line like this, there was something
|
394
432
|
# wrong with the data (404 error, new data formet, etc).
|
395
|
-
return [] if body !~ /Date,Open,High,Low,Close,Volume,Adj
|
433
|
+
return [] if body !~ /Date,Open,High,Low,Close,Volume,Adj Close/
|
396
434
|
|
397
435
|
# Parse into an array of arrays.
|
398
436
|
rows = CSV.parse( body )
|
metadata
CHANGED
@@ -3,12 +3,12 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: yahoofinance
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.2.
|
7
|
-
date:
|
6
|
+
version: 1.2.1
|
7
|
+
date: 2007-02-14 00:00:00 +01:00
|
8
8
|
summary: A package for retrieving stock quote information from Yahoo! Finance.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
email: nick @nospam@
|
11
|
+
email: nick @nospam@ transparentech.com
|
12
12
|
homepage:
|
13
13
|
rubyforge_project:
|
14
14
|
description:
|