I have a python webservice that is suppose to receive a GET request from the browser, writes some data into a csv file and serves it back to the browser.
I am struggling with this last step. How can I serve the file back to the browser? Is there a way to do it without creating or keeping the csv file on the server?
@app.route('/', methods = ['GET'])
def get_file():
alldata = []
while len(new_data) > 0:
new_data = api.timeline(max_id=oldest)
alldata.extend(new_data)
oldest = alldata[-1].id - 1
outdata = [[info.id_str] for data in alldata]
#write the csv
with open('data.csv', 'wb') as f:
writer = csv.writer(f)
writer.writerows(outdata)
pass
if __name__ == '__main__':
app.run(host = app.config['HOST'], port = app.config['PORT'])