-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomplete_workflow.py
More file actions
84 lines (66 loc) · 2.24 KB
/
complete_workflow.py
File metadata and controls
84 lines (66 loc) · 2.24 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
Complete Workflow Example
Demonstrates a real-world use case combining multiple features:
- Data extraction with pagination
- Scheduling
- Webhooks
- Execution history
"""
import asyncio
import os
import sys
from dotenv import load_dotenv
from maxun import Extract, Config
async def main():
print("=== Complete Workflow Example ===\n")
extractor = Extract(Config(
api_key=os.environ["MAXUN_API_KEY"],
base_url=os.environ.get("MAXUN_BASE_URL", "https://app.maxun.dev/api/sdk/"),
))
print("Creating full extraction robot...")
robot = await (
extractor
.create("Trending Books Daily")
.navigate("https://openlibrary.org/trending/daily")
.capture_list(
{
"selector": "li.searchResultItem.sri--w-main",
"pagination": {
"type": "clickNext",
"selector": 'a[data-ol-link-track="Pager|Next"]',
},
"maxItems": 25,
}
)
)
print(f"✓ Robot created: {robot.id}\n")
print("Setting up webhook for notifications...")
await robot.add_webhook({
"url": "https://your-webhook-endpoint.com/notifications",
"events": ["run.completed", "run.failed"],
})
print("✓ Webhook configured\n")
print("Scheduling robot to run every day...")
await robot.schedule({
"runEvery": 1,
"runEveryUnit": "DAYS",
"timezone": "UTC",
})
print("✓ Robot scheduled\n")
print("Robot Configuration Summary:")
print(f" Name: {robot.name}")
print(f" ID: {robot.id}")
schedule = robot.get_schedule()
print(f" Schedule: Every {schedule.get('runEvery')} {schedule.get('runEveryUnit')}")
webhooks = robot.get_webhooks()
print(f" Webhooks: {len(webhooks or [])} configured\n")
print("Fetching execution history...")
runs = await robot.get_runs()
print(f"✓ Found {len(runs)} runs:")
for i, run in enumerate(runs[:5], 1):
print(f" {i}. {run.get('runId')} - {run.get('status')} - {run.get('startedAt')}")
load_dotenv()
if not os.environ.get("MAXUN_API_KEY"):
print("Error: MAXUN_API_KEY environment variable is required", file=sys.stderr)
sys.exit(1)
asyncio.run(main())