All pastes #1983990 Raw Edit

Kyle Isom

public python v1 · immutable
#1983990 ·published 2010-11-07 00:21 UTC
rendered paste body
#!/usr/bin/env python"""kisom - basic utilities for dealing with ticker symbols and stocks. """import reimport urllib2def validate_stock_symbol_list(stock_list):    """    stock_list should be a list of possible stock symbols.        returns the list of stock symbols that are valid.        this function does not really check the stock_list for insane potential    ticker symbols. The assumption is the list was generated with the    token_parser.    """    flags = 'sx'    data = get_stock_data(stock_list, flags)    _stock_list = []            for line in data:        line = eval(line)        if line[1] == 'N/A': continue        _stock_list.append(line[0])        return _stock_listdef get_stock_data(stock_list, flags):    API_url = 'http://finance.yahoo.com/d/quotes.csv?s=%s&f=' + flags    _stocks     = ''        for stock in stock_list:        _stocks += stock        _stocks += '+'        _stocks.rstrip('+')        url = API_url % _stocks    data = urllib2.urlopen(url).read()    data = data.split('\r\n')               # CSV uses windows line breaks    data.pop()    return data"""Best resource for digging up flags ishttp://www.gummy-stuff.org/Yahoo-data.htm"""