Last active
December 28, 2015 08:59
-
-
Save jonnyace/7475500 to your computer and use it in GitHub Desktop.
Pulls a stock price from a ticker
This file contains 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
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