Skip to content

Instantly share code, notes, and snippets.

@JimmyMow
Created March 29, 2016 16:10
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 JimmyMow/ba1bf3c22c422d09381c to your computer and use it in GitHub Desktop.
Save JimmyMow/ba1bf3c22c422d09381c to your computer and use it in GitHub Desktop.
Given a ticker symbol return the name of the company. This uses Google's finance API
import urllib2
import re
url = 'http://www.google.com/finance/info?infotype=infoquoteall&q='
def get_name(ticker):
try:
response = urllib2.urlopen(url+ticker)
except:
print("Oops! Looks like we don't support that ticker.")
return
data = response.read()
match = re.search('"name" : ".(.*?)"', data)
if match:
name = match.group().split(':')[1].translate(None, '!@#$%^&*",.').strip()
print(name)
return
else:
print("Oops! Looks like we couldn't find a name for you.")
return
print("WMT")
get_name('WMT')
print("------------------------------------")
print("F")
get_name('F')
print("------------------------------------")
print("MMM")
get_name('MMM')
print("------------------------------------")
print("XXX")
get_name('XXX')
print("------------------------------------")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment