So I found a lot of good info on here from how to download data from GAE to a csv.. where I'm stuck is how to export multiple csv files
Summary: I have a webapp that takes multiple inputs and for each input, it sends data to the datastore and then writes from the datastore to the csv. Sample code is below:
class RunScript(webapp2.RequestHandler):
def post(self):
listOfTickers = self.request.get('Stocks').split(", ")
for i in listOfTickers:
self.main(cgi.escape(i))
main method calls other functions to get the data and ends up writing to csv via the code below:
item_query=Item.query().order(Item.keyOfItem).fetch()
self.response.headers['Content-Type'] = 'text/csv'
self.response.headers['Content-Disposition'] = 'attachment; filename=file.csv'
writer = csv.writer(self.response.out)
for a in item_query:
rowToWrite=a.row+a.value
writer.writerow(rowToWrite)
#empty datastore as data is drawn out
a.key.delete()
at this point, the sub function ends and we go back to the for loop in the post() function. I thought the sub function ending would trigger GAE to download the first csv and then download the second csv after it goes through the code again. However, what happens is I get one csv at the end with both sets of data in it.
Any thoughts as to why this is happening? Any help is appreciated!