import sys
from json import loads
from urllib.request import urlopen

def get_stock_value(stock):

    try:
        url = urlopen("https://www.google.com/finance/info?q=%s" % stock.upper()).read()
    except:
        print ("Can't find stock %s." % stock)
    else:
        page = url.decode("utf-8")

        ## remove non json symbol
        data = loads(''.join([i for i in page.splitlines() if i not in ('// [', ']')]))

        return data
        #print (data['t'], '\t', data['c'], data['cp']+'%')
    finally:
        pass


if __name__ == '__main__':

    for i in range(1,len(sys.argv)):
        stock = get_stock_value(sys.argv[i])
        if stock != None:
            print (stock['t'], '\t', stock['c'], stock['cp']+'%')
