-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy path03_dataset_exports.py
More file actions
31 lines (24 loc) · 968 Bytes
/
03_dataset_exports.py
File metadata and controls
31 lines (24 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from apify import Actor
async def main() -> None:
async with Actor:
# Open a dataset and write some data in it
dataset = await Actor.open_dataset(name='my-cool-dataset')
await dataset.push_data([{'itemNo': i} for i in range(1000)])
# Export the data as CSV
await dataset.export_to(
content_type='csv',
key='data.csv',
to_kvs_name='my-cool-key-value-store',
)
# Export the data as JSON
await dataset.export_to(
content_type='json',
key='data.json',
to_kvs_name='my-cool-key-value-store',
)
# Print the exported records
store = await Actor.open_key_value_store(name='my-cool-key-value-store')
csv_data = await store.get_value('data.csv')
Actor.log.info(f'CSV data: {csv_data}')
json_data = await store.get_value('data.json')
Actor.log.info(f'JSON data: {json_data}')