Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine the way to handle the CSV or other file #23

Open
dadiorchen opened this issue Dec 21, 2021 · 1 comment
Open

Refine the way to handle the CSV or other file #23

dadiorchen opened this issue Dec 21, 2021 · 1 comment
Labels
csv good first issue Good for newcomers

Comments

@dadiorchen
Copy link
Contributor

Now we are handling the CSV in-memory (string in memory), so maybe we need to use a better way to handle this, especially when the data is big, (maybe stream or so)

@dadiorchen dadiorchen added good first issue Good for newcomers csv labels Dec 21, 2021
@dadiorchen
Copy link
Contributor Author

try:
# convert lines to file like object
f = io.StringIO("\n".join(lines))
date = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
file_name = f"capture_{year_month}.csv"
r = requests.post('https://dev-ckan.treetracker.org/api/3/action/resource_create',
data={
"package_id":"7753e581-6e93-4eb2-8dea-4ca31f0c4d24",
"url": "http://test.com/sample.csv",
"name": file_name,
"format": "CSV",
},
headers={"X-CKAN-API-Key": "270a5f9e-9319-4f5a-983c-1fa50087fa2d"},
files=[('upload', f)]
# files={'report.xls': f}
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
csv good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant