import yahoo_finance def parse_share(msg): if len(msg.split()) > 1: print(msg.split()[1:]) try: res = '' for s in msg.split()[1:]: res = '{}\n\n{}'.format(res, get_stock(s)) except yahoo_finance.YQLResponseMalformedError: res = '```Please input valid shares: !stock [share_name]```' return res return '```Please input at least one valid share: !stock [share_name]```' def get_stock(share_name): share = yahoo_finance.Share(share_name) open_price = share.get_open() curr_price = share.get_price() change = curr_price - open_price return '```Stock: {}\n\nOpen: ${}\nCurrently: ${}\nChange:```'.format( share_name.upper(), open_price, curr_price)