Exodeus
Exodeus
WWindmill
Created by Exodeus on 11/15/2023 in #help
Download csv file from python script + app
Whoa! What responsiveness! Iā€™m in awe haha! I see with our service si for pulled šŸ™‚
11 replies
WWindmill
Created by Exodeus on 11/15/2023 in #help
Download csv file from python script + app
I have an app, which gets an external service. I retrieve a list of data that I reformat and display in a Rich Result. I would like to be able to download this data in csv format. So I have a little script to format it in csv via python:
import csv
import base64

def main(data: list):
file_path = 'file.csv'
if not data:
raise ValueError("No data")
with open(file_path, mode='w', newline='') as file:
writer = csv.DictWriter(file, fieldnames=data[0].keys())
writer.writeheader()
writer.writerows(data)

with open(file_path, 'rb') as file:
return base64.b64encode(file.read()).decode()
import csv
import base64

def main(data: list):
file_path = 'file.csv'
if not data:
raise ValueError("No data")
with open(file_path, mode='w', newline='') as file:
writer = csv.DictWriter(file, fieldnames=data[0].keys())
writer.writeheader()
writer.writerows(data)

with open(file_path, 'rb') as file:
return base64.b64encode(file.read()).decode()
Whether I return this data in base64 format directly, or whether I store it in a variable to use a Download Button, I cannot recover my formatted data in csv. The best I got was an html file....
11 replies