def loadStock(stock):
'''
Use this to dynamically pull a stock:
'''
stockFile =[]
try:
print('Currently Pulling',stock)
urlToVisit = 'http://chartapi.finance.yahoo.com/instrument/1.0/'+stock+'/chartdata;type=quote;range=10y/csv'
print('URL', urlToVisit)
try:
sourceCode = urllib.request.urlopen(urlToVisit).read().decode()
splitSource = sourceCode.split('\n')
for eachLine in splitSource:
splitLine = eachLine.split(',')
if len(splitLine)==6:
if 'values' not in eachLine:
stockFile.append(eachLine)
except Exception as e:
print(str(e), 'failed to organize pulled data.')
except Exception as e:
print(str(e), 'failed to pull pricing data')
return stockFile
评论列表
文章目录