Basically trying to modify the this tutorial for Currency's instead of stocks: http://pythonprogramming.net/advanced-matplotlib-graphing-charting-tutorial/
with my current code I get:
Error: main loop can only concatenate tuple (not "str") to tuple
The code:
import urllib2
import time
CurrencysToPull = 'audusd','eurusd','usdcad'
def pullData(Currency):
try:
fileline = Currency+'.txt'
urlToVisit = 'http://finance.yahoo.com/echarts?s=Currency=X#{"allowChartStacking":true}/'+Currency+'/chartdata;type=quote:range=1y/csv'
sourcecode = urllib2.urlopen(urlToVisit).read()
splitSource = sourcecode.split('\n')
for eachLine in splitSource:
splitLine = eachLine.split(',')
if len(splitLine)==6:
if 'valuse' not in eachLine:
saveFile = open(fileLine,'a')
lineToWrite = eachLine+'\n'
saveFile.write(lineToWrite)
print 'Pulled', Currency
print 'sleeping'
time.sleep(1)
except Exception,(e):
print('main loop'), str(e)
for eachStock in CurrencysToPull:
pullData(CurrencysToPull)
You are passing in the
CurrencysToPull
tuple to your function:which you then try to concatenate a string to:
You probably meant to pass in
eachStock
instead: