Skip to content

Instantly share code, notes, and snippets.

View microprediction's full-sized avatar

Peter Cotton microprediction

View GitHub Profile
@ChromoX
ChromoX / gist:095b81002ed8aef7b2e0
Created September 17, 2014 19:15
CUSIP to Equity Symbol
def cusip_to_symbol(cusip):
req = requests.get("http://activequote.fidelity.com/mmnet/SymLookup.phtml?reqforlookup=REQUESTFORLOOKUP&productid=mmnet&isLoggedIn=mmnet&rows=50&for=stock&by=cusip&criteria=%s&submit=Search" % (cusip))
page_html = req.text
s_index_begin = page_html.find('<tr><td height="20" nowrap><font class="smallfont">')
s_index_end = page_html.find('</table></td></tr>', s_index_begin)
symbol_section = page_html[s_index_begin:s_index_end]
s_bracket_end = symbol_section.find('</a>')
s_bracket_begin = symbol_section.find('">', s_bracket_end - 10)
return symbol_section[s_bracket_begin + len('">'):s_bracket_end]