Skip to content

Implement Google quote functionality #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pandas_datareader/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import warnings

from pandas_datareader.google.daily import GoogleDailyReader
from pandas_datareader.google.quotes import _get_data as get_quote_google # noqa
from pandas_datareader.google.quotes import GoogleQuotesReader

from pandas_datareader.yahoo.daily import YahooDailyReader
from pandas_datareader.yahoo.quotes import YahooQuotesReader
Expand Down Expand Up @@ -44,6 +44,10 @@ def get_quote_yahoo(*args, **kwargs):
return YahooQuotesReader(*args, **kwargs).read()


def get_quote_google(*args, **kwargs):
return GoogleQuotesReader(*args, **kwargs).read()


def DataReader(name, data_source=None, start=None, end=None,
retry_count=3, pause=0.001, session=None):
"""
Expand Down
35 changes: 27 additions & 8 deletions pandas_datareader/google/quotes.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
def _get_data(symbols):
"""
Get current yahoo quote
import pandas
from pandas_datareader.base import _BaseReader
import json
import re

(Should) Returns a DataFrame

ToDo: Not implemented
"""
msg = "Google Finance doesn't have this functionality - can't get quote for %s" % symbols
raise NotImplementedError(msg)
class GoogleQuotesReader(_BaseReader):

"""Get current google quote"""

@property
def url(self):
return 'http://www.google.com/finance/info'

@property
def params(self):
if isinstance(self.symbols, pandas.compat.string_types):
sym_list = self.symbols
else:
sym_list = ','.join(self.symbols)
params = {'q': sym_list}
return params

def _read_lines(self, out):
buffer = out.read()
m = re.search('// ', buffer)
result = json.loads(buffer[m.start() + len('// '):])
return pandas.DataFrame(map(lambda x: float(x['l']), result),
index=map(lambda x: x['t'], result))
6 changes: 3 additions & 3 deletions pandas_datareader/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def test_google(self):
self.assertRaises(Exception, web.DataReader, "NON EXISTENT TICKER",
'google', start, end)

def test_get_quote_fails(self):
self.assertRaises(NotImplementedError, web.get_quote_google,
pd.Series(['GOOG', 'AAPL', 'GOOG']))
def test_get_quote_stringlist(self):
df = web.get_quote_google(['GOOG', 'AMZN', 'GOOG'])
assert_series_equal(df.ix[0], df.ix[2])

def test_get_goog_volume(self):
for locale in self.locales:
Expand Down