Skip to content

Instantly share code, notes, and snippets.

@ishahid
Last active February 8, 2016 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishahid/9f0823c19b6d387529f4 to your computer and use it in GitHub Desktop.
Save ishahid/9f0823c19b6d387529f4 to your computer and use it in GitHub Desktop.
Get quote from stock market using Google Finance
#!/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