""" Python module for use in the SoCal Linux Expo exhibit. project builtin functions. """ from PsychePostProcessor import PsychePostProcessor import urllib, string class PsycheStock( PsychePostProcessor ): def __init__( self, input_args ): symbols = input_args[0] self.get_stock( symbols ) def get_stock( self, symbols ): self.quotelist = {} getstocks = 'http://finance.yahoo.com/d/quotes.csv'+\ '?f=sl1&e=.csv&s=' + symbols stockquotes = urllib.urlopen( getstocks ) stocklist = stockquotes.read() quote = stocklist.split( "\r\n" ) for a in range( 0, len(quote) - 1 ): stock, price = quote[a].split( ',' ) stock = stock.strip( '"' ) self.quotelist[stock] = price urllib.urlcleanup() output = [] for key in self.quotelist.keys(): output.append('%s %s,'% (string.join(list(key)), self.quotelist[key])) self.set_result(string.join(output).rstrip(',')+'\n') ################################################################################ if __name__ == '__main__': pp = PsycheStock( ['amd+sunw+ba+tmta+brka+pfe'] ) print pp.get_result()