Query real-time traffic data from TomTom for any route and provide the user with actionable travel advice. The script handles geocoding (resolving place names to coordinates) and routing (calculating travel time with live traffic) — all via the same TomTom API key.
The origin and destination are not static — you must determine them from what the user tells you. Examples:
Rules:
Execute the script with origin and destination as arguments:
python3 {baseDir}/scripts/check_traffic.py --origin "<ORIGIN>" --destination "<DESTINATION>"
Examples:
python3 {baseDir}/scripts/check_traffic.py --origin "Basel, Switzerland" --destination "Zurich, Switzerland"
python3 {baseDir}/scripts/check_traffic.py --origin "Basel SBB" --destination "Paradeplatz, Zürich"
python3 {baseDir}/scripts/check_traffic.py --origin "Aeschenplatz, Basel" --destination "ETH Zürich"
The script returns JSON with one or more route alternatives. For each route:
| Field | Meaning |
|---|---|
| ------- | --------- |
travel_time_min | Total travel time with current live traffic |
no_traffic_time_min | Travel time with zero traffic (free-flow) |
historic_traffic_time_min | Typical travel time based on historical patterns |
live_traffic_time_min | Time including live incident data |
traffic_delay_min | Extra delay caused by current traffic |
traffic_delay_pct | Delay as percentage of free-flow time |
congestion | Derived level: light, moderate, or heavy |
distance_km | Route distance in kilometers |
departure_time / arrival_time | Departure and estimated arrival timestamps |
When presenting traffic data, always include:
Keep it concise and practical. The user wants to know: "How long will it take and should I go now?"
{"status": "error"}, relay the error message to the user.TOMTOM_API_KEY is not configured, tell the user to set it up in ~/.openclaw/openclaw.json.共 1 个版本