Flight Monitor Skill
查询国内外实时机票价格,设置低价提醒,支持定时监控。无需浏览器自动化,无需 API 密钥。
Quick Start
单程查询
CODEBLOCK0
往返查询
CODEBLOCK1
设置价格监控与推送
CODEBLOCK2
管理监控任务
CODEBLOCK3
配置手机推送
CODEBLOCK4
Core Workflow
Step 1 — Parse User Intent
Extract these parameters from the user's message:
| Parameter | Required | Example |
|---|
| 出发城市 dep | Yes | 北京 / BJS |
| 到达城市 arr |
Yes | 三亚 / SYX |
| 出发日期 date | Yes | 2026-04-10 |
| 返程日期 return_date | Round-trip only | 2026-04-15 |
| 最高价 max_price | No | 700 |
| 监控频率 freq | For monitoring | daily / 6h |
City name→code resolution is handled automatically by the scripts.
For cities not recognized, check references/city_codes.md.
Step 2 — Query Flight Data
⚠️ CRITICAL DATE RULE: Always use the user's exact travel date. NEVER substitute today's date.
Step 2a — Run search_flights.py (always do this first)
CODEBLOCK5
The script tries three data sources in order and returns one of:
| Result INLINECODE1 | What it means | What you do next |
|---|
| INLINECODE2 | Full flight list fetched directly — done | Format the flights list into a table. Skip all web searches. |
| INLINECODE4 |
Lowest price summary only (no schedule) | Show the price summary + booking links.
Skip all web searches. |
|
fallback | APIs unavailable | Do
exactly ONE web_search using the
search_query field. Then stop.
Do NOT fetch any URLs. |
Step 2b — Fallback web_search (only when source == "fallback")
Use the exact query string from search_query in the script output:
CODEBLOCK6
Parse snippets for: airline name, flight number, departure time, arrival time, price.
Stop after this one search, regardless of result quality. Use whatever data the snippets contain.
HARD RULES — no exceptions
- - NEVER call
web_fetch on any URL (携程/去哪儿/Skyscanner are all JS-rendered; fetching wastes time and returns nothing useful). - NEVER run more than 1
web_search per query direction (outbound / return). - NEVER try multiple search engines or reformulate the query if the first search returns partial data.
- If data is incomplete after one search, present what you have and note the limitation.
Step 3 — Record Price History
After querying, always record the result for trend tracking:
CODEBLOCK7
History files: INLINECODE11
Step 4 — Check Alert & Send Notification
After recording, check if the price is at or below threshold:
CODEBLOCK8
If the output contains "低价提醒" (price ≤ threshold):
CODEBLOCK9
notify.py will automatically use whichever push service is configured.
If no push service is configured, it will print instructions to set one up.
Step 5 — Set Up Monitoring (when user requests recurring checks)
CODEBLOCK10
Monitor tasks are saved as TOML files under ~/.workbuddy/automations/.
Security notes:
- -
monitor_manager.py does not import os and contains no os.system() / subprocess calls. - All
--id arguments are validated against a strict whitelist regex (flight-[A-Z]+-[A-Z]+-YYYY-MM-DD) before any filesystem access, preventing path traversal attacks. - The
run subcommand only prints a safe hint — it never executes external commands.
Push Notification Setup
Three free services are supported. Configure one:
Option A — Bark (iOS only, recommended for iPhone users)
- 1. Install Bark app from App Store
- Open the app → copy your device key
- Configure: INLINECODE20
Option B — Server酱 (WeChat notification, Android & iOS)
- 1. Visit https://sct.ftqq.com/ and login with GitHub
- Copy your SendKey
- Configure: INLINECODE21
Option C — PushDeer (open source, Android & iOS)
- 1. Install PushDeer app or use web version at https://www.pushdeer.com/
- Create a device and copy the push key
- Configure: INLINECODE22
Configuration is saved to ~/.workbuddy/flight-monitor/notify_config.json.
Frequency Options
| Input | Schedule | Label |
|---|
| INLINECODE24 / INLINECODE25 | Every 1 hour | 每1小时 |
| INLINECODE26 |
Every 2 hours | 每2小时 |
|
3h | Every 3 hours | 每3小时 |
|
6h | Every 6 hours | 每6小时 |
|
12h /
twice-daily | Every 12 hours | 每12小时 |
|
daily /
morning | Daily at 09:00 CST | 每天9:00 |
Recommended frequencies by lead time:
| Lead Time | Recommended Freq |
|---|
| 1 month+ | daily |
| 2 weeks |
12h |
| 1 week | 6h |
| 3 days | 3h |
Output Format
Query Result (shown to user)
Always present results in the following table format. For connecting flights, the
"中转" column must list the connection city and layover wait time (e.g. "转上海 1h20m").
CODEBLOCK11
Column definitions:
- -
全程时长: total elapsed time from departure to final arrival (including layover) - INLINECODE34 : for connecting flights, list connection city + layover wait duration; write "直飞" for non-stop
Low-Price Alert (sent to phone)
CODEBLOCK12
Notes
- - ⚠️ Date discipline: Always search for the user's exact travel date. The travel date is NOT today's date.
- Query flow: Always start with
search_flights.py. Only fall back to web_search when the script returns source: fallback. Maximum 1 search per direction. - Never use webfetch: All major OTA sites (携程, 去哪儿, Skyscanner) are JavaScript-rendered. Fetching them returns empty or useless content and wastes tokens.
- Data source priority: Ctrip AJAX API (richest, no key) → zbape.com (key required, lowest-price only) → single websearch fallback.
- zbape key (optional): Run
python scripts/search_flights.py --setup-zbape <KEY> once. Adds a useful lowest-price-per-date layer when the Ctrip API is rate-limited. - Push notifications: Configure once, alerts fire automatically on every monitoring cycle when price drops below threshold.
- City codes: See
references/city_codes.md for the full list.
File Overview
CODEBLOCK13
Optional: zbape API key (adds lowest-price-per-date data when Ctrip API fails)
CODEBLOCK14
机票监控技能
查询国内外实时机票价格,设置低价提醒,支持定时监控。无需浏览器自动化,无需 API 密钥。
快速开始
单程查询
查一下北京到三亚 3 月 25 日的机票价格
Check flights from BJS to SYX on 2026-03-25
查询杭州到西安 3 月 26 日,低于 500 元的机票
往返查询
帮我看看上海飞成都,4 月 1 日去 4 月 5 日回
上海到成都下周六往返票
设置价格监控与推送
监控赣州到哈尔滨 4 月 10 日,每天查一次,低于 700 提醒我
Monitor BJS to SYX on 2026-03-25, daily, alert if under ¥1500
管理监控任务
查看我所有的机票监控任务
暂停北京到三亚的监控
删除杭州到西安的监控任务
配置手机推送
设置推送 Bark Key: xxxxx
核心工作流程
第一步 — 解析用户意图
从用户消息中提取以下参数:
| 参数 | 是否必需 | 示例 |
|---|
| 出发城市 dep | 是 | 北京 / BJS |
| 到达城市 arr |
是 | 三亚 / SYX |
| 出发日期 date | 是 | 2026-04-10 |
| 返程日期 return_date | 仅往返 | 2026-04-15 |
| 最高价 max_price | 否 | 700 |
| 监控频率 freq | 监控时使用 | daily / 6h |
城市名称到代码的解析由脚本自动处理。
对于无法识别的城市,请查看 references/city_codes.md。
第二步 — 查询航班数据
⚠️ 关键日期规则:始终使用用户的确切出行日期。切勿用今天的日期替代。
第 2a 步 — 运行 search_flights.py(始终先执行此步骤)
bash
python scripts/search_flights.py --from --to --date
python scripts/search_flights.py --from KOW --to HRB --date 2026-04-10 --max-price 700
python scripts/search_flights.py --from SHA --to CTU --date 2026-04-01 --return-date 2026-04-05
脚本按顺序尝试三个数据源,并返回以下之一:
| 结果 source | 含义 | 下一步操作 |
|---|
| ctrip | 直接获取完整航班列表 — 完成 | 将 flights 列表格式化为表格。跳过所有网络搜索。 |
| zbape |
仅最低价摘要(无时刻表) | 显示价格摘要 + 预订链接。
跳过所有网络搜索。 |
| fallback | API 不可用 | 使用 search
query 字段执行恰好一次 websearch。然后停止。
不要获取任何 URL。 |
第 2b 步 — 备用 web_search(仅当 source == fallback 时)
使用脚本输出中 search_query 的确切查询字符串:
websearch(query 字段的值>)
解析摘要片段以获取:航空公司名称、航班号、出发时间、到达时间、价格。
在此一次搜索后停止,无论结果质量如何。使用片段中包含的任何数据。
硬性规则 — 无例外
- - 切勿调用 webfetch 获取任何 URL(携程/去哪儿/Skyscanner 均为 JS 渲染;获取会浪费时间且返回无用的内容)。
- 每次查询方向(去程/返程)最多执行 1 次 websearch。
- 切勿尝试多个搜索引擎或在第一次搜索返回部分数据时重新组织查询语句。
- 如果一次搜索后数据不完整,请展示已有数据并说明限制。
第三步 — 记录价格历史
查询后,始终记录结果以便追踪趋势:
bash
python scripts/price_history.py append \
--from KOW --to HRB --date 2026-04-10 \
--price <找到的最低价格> --flight <航班号> --threshold 700
查看某条航线的历史记录
python scripts/price_history.py show --from KOW --to HRB --date 2026-04-10
列出所有有历史记录的航线
python scripts/price_history.py list
历史文件:~/.workbuddy/flight-monitor/{DEP}-{ARR}-{DATE}.json
第四步 — 检查提醒并发送通知
记录后,检查价格是否达到或低于阈值:
bash
python scripts/price_history.py show --from KOW --to HRB --date 2026-04-10
如果输出包含低价提醒(价格 ≤ 阈值):
bash
python scripts/notify.py \
--title 机票低价提醒 KOW→HRB \
--body 赣州→哈尔滨 2026-04-10 最低价 ¥,低于阈值¥700!推荐航班 \
--url https://flights.ctrip.com/itinerary/oneway/kow-hrb?depdate=2026-04-10
notify.py 将自动使用已配置的任何推送服务。
如果未配置推送服务,它将打印设置说明。
第五步 — 设置监控(当用户请求定期检查时)
bash
添加每日监控并设置价格提醒
python scripts/monitor_manager.py add \
--from KOW --to HRB --date 2026-04-10 \
--freq daily --threshold 700
每 6 小时
python scripts/monitor_manager.py add \
--from HGH --to SIA --date 2026-03-26 --freq 6h
列出所有监控任务
python scripts/monitor_manager.py list
暂停监控
python scripts/monitor_manager.py pause --id flight-KOW-HRB-2026-04-10
删除监控
python scripts/monitor_manager.py remove --id flight-KOW-HRB-2026-04-10
显示详情 / 手动触发提示(不执行任何 shell 命令)
python scripts/monitor_manager.py run --id flight-KOW-HRB-2026-04-10
监控任务以 TOML 文件形式保存在 ~/.workbuddy/automations/ 下。
安全说明:
- - monitor_manager.py 不导入 os,且不包含任何 os.system() / subprocess 调用。
- 所有 --id 参数在访问文件系统之前,都会通过严格的白名单正则表达式(flight-[A-Z]+-[A-Z]+-YYYY-MM-DD)进行验证,防止路径遍历攻击。
- run 子命令仅打印安全提示 — 它从不执行外部命令。
推送通知设置
支持三种免费服务。配置其中一种:
选项 A — Bark(仅 iOS,推荐 iPhone 用户)
- 1. 从 App Store 安装 Bark 应用
- 打开应用 → 复制您的设备密钥
- 配置:python scripts/notify.py --setup bark --key <您的密钥>
选项 B — Server酱(微信通知,Android 和 iOS)
- 1. 访问 https://sct.ftqq.com/ 并使用 GitHub 登录
- 复制您的 SendKey
- 配置:python scripts/notify.py --setup serverchan --key <您的 SendKey>
选项 C — PushDeer(开源,Android 和 iOS)
- 1. 安装 PushDeer 应用或使用网页版 https://www.pushdeer.com/
- 创建设备并复制推送密钥
- 配置:python scripts/notify.py --setup pushdeer --key <您的密钥>
配置保存至 ~/.workbuddy/flight-monitor/notify_config.json。
频率选项
| 输入 | 计划 | 标签 |
|---|
| hourly / 1h | 每 1 小时 | 每1小时 |
| 2h |
每 2 小时 | 每2小时 |
| 3h | 每 3 小时 | 每3小时 |
| 6h | 每 6 小时 | 每6小时 |
| 12h / twice-daily | 每 12 小时 | 每12小时 |
| daily / morning | 每天 09:00 CST | 每天9:00 |
根据提前期推荐频率:
12h |