Skip to content

Instantly share code, notes, and snippets.

@jonnyace
Last active December 28, 2015 08:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonnyace/7475500 to your computer and use it in GitHub Desktop.
Save jonnyace/7475500 to your computer and use it in GitHub Desktop.
Pulls a stock price from a ticker
import urllib
import re
def get_quote(symbol):
base_url = 'http://finance.google.com/finance?q='
content = urllib.urlopen(base_url + symbol).read()
m = re.search('id="ref_694653_l".*?>(.*?)<', content)
if m:
quote = m.group(1)
else:
quote = 'no quote available for: ' + symbol
return quote
# printing a predefined ticker was easy.
print "Google", get_quote('goog')
from sys import argv
print "Enter your stock ticker" # how do I get this to reference the get function above?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment