Last active
February 8, 2016 02:32
-
-
Save ishahid/9f0823c19b6d387529f4 to your computer and use it in GitHub Desktop.
Get quote from stock market using Google Finance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
"""Get quote from stock market using Google Finance | |
https://gist.github.com/ishahid/9f0823c19b6d387529f4 | |
""" | |
try: | |
import os, sys | |
import json | |
import googlefinance as google | |
except ImportError: | |
print 'Required dependencies not installed.' | |
print 'Run the following commands...' | |
print '$ sudo pip install googlefinance' | |
exit() | |
def get_quote(symbol): | |
return google.getQuotes(symbol) | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
print 'Usage: quote.py <symbol>' + os.linesep | |
else: | |
try: | |
q = get_quote(sys.argv[1]) | |
msg = '%s:%s %s %s%s' % ( | |
q[0]['Index'], q[0]['StockSymbol'], | |
q[0]['LastTradePrice'], q[0]['LastTradeDateTimeLong'], | |
os.linesep | |
) | |
print msg | |
except: | |
print 'Invalid symbol...' | |
print 'Usage: quote.py <symbol>' + os.linesep |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment