mirror of
https://github.com/hongtaocai/googlefinance.git
synced 2024-06-25 14:29:40 -05:00
support py3 and minimally test
This commit is contained in:
parent
997f1eadf0
commit
960658e9c5
14
.travis.yml
Normal file
14
.travis.yml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
language: python
|
||||||
|
|
||||||
|
python:
|
||||||
|
- "2.6"
|
||||||
|
- "2.7"
|
||||||
|
- "pypy"
|
||||||
|
- "3.3"
|
||||||
|
- "3.4"
|
||||||
|
|
||||||
|
install:
|
||||||
|
- python setup.py install
|
||||||
|
|
||||||
|
script:
|
||||||
|
- nosetests
|
|
@ -1,7 +1,11 @@
|
||||||
from urllib2 import Request, urlopen
|
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
try:
|
||||||
|
from urllib.request import Request, urlopen
|
||||||
|
except ImportError: # python 2
|
||||||
|
from urllib2 import Request, urlopen
|
||||||
|
|
||||||
__author__ = 'Hongtao Cai'
|
__author__ = 'Hongtao Cai'
|
||||||
|
|
||||||
googleFinanceKeyToFullName = {
|
googleFinanceKeyToFullName = {
|
||||||
|
@ -48,16 +52,16 @@ def getQuotes(symbols):
|
||||||
get real-time quotes (index, last trade price, last trade time, etc) for stocks, using google api: http://finance.google.com/finance/info?client=ig&q=symbols
|
get real-time quotes (index, last trade price, last trade time, etc) for stocks, using google api: http://finance.google.com/finance/info?client=ig&q=symbols
|
||||||
|
|
||||||
Unlike python package 'yahoo-finance' (15 min delay), There is no delay for NYSE and NASDAQ stocks in 'googlefinance' package.
|
Unlike python package 'yahoo-finance' (15 min delay), There is no delay for NYSE and NASDAQ stocks in 'googlefinance' package.
|
||||||
|
|
||||||
example:
|
example:
|
||||||
quotes = getQuotes('AAPL')
|
quotes = getQuotes('AAPL')
|
||||||
return:
|
return:
|
||||||
[{u'Index': u'NASDAQ', u'LastTradeWithCurrency': u'129.09', u'LastTradeDateTime': u'2015-03-02T16:04:29Z', u'LastTradePrice': u'129.09', u'Yield': u'1.46', u'LastTradeTime': u'4:04PM EST', u'LastTradeDateTimeLong': u'Mar 2, 4:04PM EST', u'Dividend': u'0.47', u'StockSymbol': u'AAPL', u'ID': u'22144'}]
|
[{u'Index': u'NASDAQ', u'LastTradeWithCurrency': u'129.09', u'LastTradeDateTime': u'2015-03-02T16:04:29Z', u'LastTradePrice': u'129.09', u'Yield': u'1.46', u'LastTradeTime': u'4:04PM EST', u'LastTradeDateTimeLong': u'Mar 2, 4:04PM EST', u'Dividend': u'0.47', u'StockSymbol': u'AAPL', u'ID': u'22144'}]
|
||||||
|
|
||||||
quotes = getQuotes(['AAPL', 'GOOG'])
|
quotes = getQuotes(['AAPL', 'GOOG'])
|
||||||
return:
|
return:
|
||||||
[{u'Index': u'NASDAQ', u'LastTradeWithCurrency': u'129.09', u'LastTradeDateTime': u'2015-03-02T16:04:29Z', u'LastTradePrice': u'129.09', u'Yield': u'1.46', u'LastTradeTime': u'4:04PM EST', u'LastTradeDateTimeLong': u'Mar 2, 4:04PM EST', u'Dividend': u'0.47', u'StockSymbol': u'AAPL', u'ID': u'22144'}, {u'Index': u'NASDAQ', u'LastTradeWithCurrency': u'571.34', u'LastTradeDateTime': u'2015-03-02T16:04:29Z', u'LastTradePrice': u'571.34', u'Yield': u'', u'LastTradeTime': u'4:04PM EST', u'LastTradeDateTimeLong': u'Mar 2, 4:04PM EST', u'Dividend': u'', u'StockSymbol': u'GOOG', u'ID': u'304466804484872'}]
|
[{u'Index': u'NASDAQ', u'LastTradeWithCurrency': u'129.09', u'LastTradeDateTime': u'2015-03-02T16:04:29Z', u'LastTradePrice': u'129.09', u'Yield': u'1.46', u'LastTradeTime': u'4:04PM EST', u'LastTradeDateTimeLong': u'Mar 2, 4:04PM EST', u'Dividend': u'0.47', u'StockSymbol': u'AAPL', u'ID': u'22144'}, {u'Index': u'NASDAQ', u'LastTradeWithCurrency': u'571.34', u'LastTradeDateTime': u'2015-03-02T16:04:29Z', u'LastTradePrice': u'571.34', u'Yield': u'', u'LastTradeTime': u'4:04PM EST', u'LastTradeDateTimeLong': u'Mar 2, 4:04PM EST', u'Dividend': u'', u'StockSymbol': u'GOOG', u'ID': u'304466804484872'}]
|
||||||
|
|
||||||
:param symbols: a single symbol or a list of stock symbols
|
:param symbols: a single symbol or a list of stock symbols
|
||||||
:return: real-time quotes list
|
:return: real-time quotes list
|
||||||
'''
|
'''
|
||||||
|
@ -75,6 +79,6 @@ if __name__ == '__main__':
|
||||||
symbols = symbols.split(',')
|
symbols = symbols.split(',')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print json.dumps(getQuotes(symbols), indent=2)
|
print(json.dumps(getQuotes(symbols), indent=2))
|
||||||
except:
|
except:
|
||||||
print "Fail"
|
print("Fail")
|
||||||
|
|
12
setup.py
12
setup.py
|
@ -9,5 +9,15 @@ setup(
|
||||||
url = 'https://github.com/hongtaocai/googlefinance', # use the URL to the github repo
|
url = 'https://github.com/hongtaocai/googlefinance', # use the URL to the github repo
|
||||||
download_url = 'https://github.com/hongtaocai/googlefinance/tarball/0.4', # I'll explain this in a second
|
download_url = 'https://github.com/hongtaocai/googlefinance/tarball/0.4', # I'll explain this in a second
|
||||||
keywords = ['googlefinance', 'stock', 'price' , 'finance', 'google', 'real-time'], # arbitrary keywords
|
keywords = ['googlefinance', 'stock', 'price' , 'finance', 'google', 'real-time'], # arbitrary keywords
|
||||||
classifiers = [],
|
classifiers = [
|
||||||
|
'License :: OSI Approved :: MIT License',
|
||||||
|
'Operating System :: OS Independent',
|
||||||
|
'Programming Language :: Python',
|
||||||
|
'Programming Language :: Python :: 2',
|
||||||
|
'Programming Language :: Python :: 2.6',
|
||||||
|
'Programming Language :: Python :: 2.7',
|
||||||
|
'Programming Language :: Python :: 3',
|
||||||
|
'Programming Language :: Python :: 3.3',
|
||||||
|
'Programming Language :: Python :: 3.4',
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
17
tests/test_googlefinance.py
Normal file
17
tests/test_googlefinance.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import googlefinance
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
class TestQuotes(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_one_symbol(self):
|
||||||
|
appl = googlefinance.getQuotes('GOOG')[0]
|
||||||
|
self.assertEqual(appl["Index"], "NASDAQ")
|
||||||
|
self.assertEqual(appl["StockSymbol"], "GOOG")
|
||||||
|
|
||||||
|
def test_symbols(self):
|
||||||
|
quotes = googlefinance.getQuotes(['GOOG', 'VIE:BKS'])
|
||||||
|
self.assertEqual(quotes[0]["Index"], "NASDAQ")
|
||||||
|
self.assertEqual(quotes[0]["StockSymbol"], "GOOG")
|
||||||
|
self.assertEqual(quotes[1]["Index"], "VIE")
|
||||||
|
self.assertEqual(quotes[1]["StockSymbol"], "BKS")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user