Stock prices from Yahoo
Post date: May 24, 2016 4:48:07 PM
from urllib.request import urlopen
import json
import time
symbol = input("Give me a stock symbol:")
sURL = "http://finance.yahoo.com/webservice/v1/symbols/"
sURL += symbol
sURL += "/quote?format=json&view=detail"
while True:
html = urlopen(sURL)
response = html.read()
html.close
json_data = json.loads(response.decode())
stock = json_data['list']['resources'][0]['resource']['fields']
print(symbol, " price is ", stock["price"])
for key in stock:
print(key, "=", stock[key])
if float(stock["chg_percent"]) < 0:
print("Your stock is falling!!!! Sorry....")
else:
print("You are making money!!!")
time.sleep(5)