-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy path11_actor_charge.py
More file actions
36 lines (29 loc) · 898 Bytes
/
11_actor_charge.py
File metadata and controls
36 lines (29 loc) · 898 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
32
33
34
35
36
import asyncio
from apify import Actor
async def main() -> None:
async with Actor:
# highlight-start
# Charge for a single occurrence of an event
await Actor.charge(event_name='init')
# highlight-end
# Prepare some mock results
result = [
{'word': 'Lorem'},
{'word': 'Ipsum'},
{'word': 'Dolor'},
{'word': 'Sit'},
{'word': 'Amet'},
]
# highlight-start
# Shortcut for charging for each pushed dataset item
await Actor.push_data(result, 'result-item')
# highlight-end
# highlight-start
# Or you can charge for a given number of events manually
await Actor.charge(
event_name='result-item',
count=len(result),
)
# highlight-end
if __name__ == '__main__':
asyncio.run(main())