Google Flights Search
Fetch live flight data from Google Flights via SearchAPI.io, then score and rank results using the flight-scoring skill, then ALWAYS save the search via the flight-price-monitor skill for automatic price tracking.
Install
CODEBLOCK0
Requirements
- - Python 3 — uses only stdlib (
urllib, json, argparse). No pip installs needed. - SearchAPI.io account — free tier includes 100 requests/month. Sign up here.
- SEARCHAPI_KEY — get your API key from SearchAPI.io after registering, then add it to
.env at the project root. OpenClaw loads it automatically.
Quick Reference
| Situation | Action |
|---|
| User asks for flights | Run search_searchapi.py, score results, then save via INLINECODE7 |
| Round-trip search |
Add
--return-date AND
--top 5 to get return flight details |
| User says "around [date]" | Use
--days 3 centered on that date |
| User says "cheapest in March" | Use
--days 3 and pick a representative start date |
| Specific date | Use
--days 1 (or
--days 3 for ±1 flexibility) |
| Direct only | Add
--stops 0 |
| Multi-passenger | Add
--adults N |
Usage
CODEBLOCK1
All Parameters
| Parameter | Required | Default | Description |
|---|
| INLINECODE16 | Yes | — | Origin IATA code (e.g. TLV) |
| INLINECODE18 |
Yes | — | Destination IATA code (e.g.
LON,
LHR,
LGW) |
|
--date | Yes | — | Outbound date
YYYY-MM-DD |
|
--return-date | No | — | Return date
YYYY-MM-DD (makes it a round-trip search) |
|
--days | No |
1 | Number of days to search forward from
--date (max: 3) |
|
--currency | No |
USD | Currency code (
USD,
EUR,
ILS) |
|
--adults | No |
1 | Number of adult passengers |
|
--stops | No | any |
0 = direct only,
1 = up to 1 stop,
2 = up to 2 stops |
|
--class | No | economy |
1=economy,
2=premium
economy, 3=business, 4=firstclass |
|
--top | No | — | Auto-fetch return flight details for top N outbound results.
Use --top 5 for round-trips. |
|
--departure-token | No | — | Fetch return flights for a specific outbound (advanced, rarely needed directly) |
|
--booking-token | No | — | Fetch booking options (real airline/OTA URLs) for a specific flight using its
booking_token |
Destination codes
Google Flights accepts:
- - Airport codes:
LHR, CDG, INLINECODE52 - City codes:
LON (all London airports), PAR (all Paris), INLINECODE55
Use city codes when the user hasn't specified a preferred airport.
Output Format
The script prints JSON to stdout.
One-Way / Outbound Only
CODEBLOCK2
Round-Trip with --top 5 (includes return flight details)
When --top N is used with --return-date, each of the top N outbound results includes a nested return_flight object with full return leg details:
CODEBLOCK3
Important: The price is the combined round-trip price (same on both outbound and return_flight). The return_flight object has its own airline, flight number, times, layovers, and stops — use all of these when formatting results.
Booking Token Lookup (--booking-token)
After scoring, use the booking_token from each top result to fetch real booking URLs.
You must pass the same --from, --to, --date used in the original search. For round-trips, also pass --return-date.
CODEBLOCK4
Returns:
CODEBLOCK5
Use the first option whose book_with matches the airline (direct airline link). If no airline match, use the first option. If --booking-token fails or returns no options, fall back to vendor-booking-link.
Full Workflow
CODEBLOCK6
Always score before presenting. Never dump raw JSON to the user.
Always include booking links. Prefer booking_token for real URLs; fall back to vendor-booking-link if unavailable. Never link to Google Flights or aggregators.
Round-trips MUST use --top 5 to get return flight details. Without --top, only outbound info is returned.
Step 8: Save Price Monitor (MANDATORY)
After presenting results, ALWAYS save the search for price monitoring. Build a compact snapshot from the top 10-15 flights as "Airline|FlightNum|DepTime": price pairs, then run:
CODEBLOCK7
- -
--user-id: The peer ID from the session (e.g. whatsapp:+972523866782). If unknown, use the user's name. - INLINECODE78 : The channel the user is on (
whatsapp, telegram, etc.) - INLINECODE81 : The user's address on that channel. Use
last if unknown. - INLINECODE83 : JSON object of
"Airline|FlightNum|HH:MM": price pairs from the results. - Omit
--return-date if it was a one-way search.
This overwrites any previous monitor for this user. A cron job checks every 2 hours and notifies the user of price changes.
Mapping Script Output → Scoring Inputs
| Scoring field | Script field |
|---|
| Price | INLINECODE86 |
| Stops |
stops |
| Departure time |
departure_time (extract HH:MM) |
| Arrival time |
arrival_time (extract HH:MM) |
| Overnight flag |
overnight |
| Duration |
duration_minutes |
| Risky layover |
min_layover_minutes < 60 |
| Airline |
airline |
| Flight number |
flight_number |
| Route |
origin →
destination (IATA codes) |
Error Handling
| Error | Cause | Fix |
|---|
| INLINECODE97 | Missing .env entry | Add SEARCHAPI_KEY=your_key to INLINECODE100 |
| INLINECODE101 |
Invalid API key | Check key at searchapi.io |
|
HTTP 429 | Rate limit hit | Wait and retry, or use
--days in smaller batches |
| No results for a date | Route not available | Try adjacent dates or different destination airport code |
Notes
- - El Al does not fly on Shabbat — Friday evening and Saturday flights from TLV won't appear for El Al.
- Secondary airports: Wizz/Ryanair use
LTN, STN, BGY etc. — when the script returns results from these, mention the airport to the user. - Prices are per-person unless
--adults is set. For groups, multiply accordingly and note total. - Round-trip: Use
--return-date YYYY-MM-DD --top 5 to search round-trip and auto-fetch return flight details for the top 5 results.
Google Flights 搜索
通过 SearchAPI.io 从 Google Flights 获取实时航班数据,然后使用 flight-scoring 技能对结果进行评分和排名,最后务必通过 flight-price-monitor 技能保存搜索以进行自动价格追踪。
安装
bash
clawhub install google-flights-search
要求
- - Python 3 — 仅使用标准库(urllib、json、argparse)。无需 pip 安装。
- SearchAPI.io 账户 — 免费套餐包含每月 100 次请求。在此注册。
- SEARCHAPI_KEY — 注册后从 SearchAPI.io 获取 API 密钥,然后将其添加到项目根目录的 .env 文件中。OpenClaw 会自动加载。
快速参考
| 情况 | 操作 |
|---|
| 用户询问航班 | 运行 search_searchapi.py,评分结果,然后通过 flight-price-monitor 保存 |
| 往返搜索 |
添加 --return-date 和 --top 5 以获取返程航班详情 |
| 用户说大约[日期] | 使用 --days 3,以该日期为中心 |
| 用户说三月最便宜 | 使用 --days 3 并选择一个有代表性的起始日期 |
| 具体日期 | 使用 --days 1(或 --days 3 以提供 ±1 天的灵活性) |
| 仅直飞 | 添加 --stops 0 |
| 多名乘客 | 添加 --adults N |
用法
bash
单程搜索
python {baseDir}/scripts/search_searchapi.py \
--from TLV --to LON --date 2026-03-15 --days 3 --currency USD
往返搜索,获取前 5 个结果的返程航班详情(推荐用于往返行程)
python {baseDir}/scripts/search_searchapi.py \
--from TLV --to BKK --date 2026-03-28 --return-date 2026-04-14 --top 5
所有参数
| 参数 | 必需 | 默认值 | 描述 |
|---|
| --from | 是 | — | 出发地 IATA 代码(例如 TLV) |
| --to |
是 | — | 目的地 IATA 代码(例如 LON、LHR、LGW) |
| --date | 是 | — | 出发日期 YYYY-MM-DD |
| --return-date | 否 | — | 返程日期 YYYY-MM-DD(使其成为往返搜索) |
| --days | 否 | 1 | 从 --date 开始向前搜索的天数(最大:3) |
| --currency | 否 | USD | 货币代码(USD、EUR、ILS) |
| --adults | 否 | 1 | 成人乘客数量 |
| --stops | 否 | 任意 | 0 = 仅直飞,1 = 最多 1 次中转,2 = 最多 2 次中转 |
| --class | 否 | economy | 1=经济舱,2=高级经济舱,3=商务舱,4=头等舱 |
| --top | 否 | — | 自动获取前 N 个去程结果的返程航班详情。
往返行程使用 --top 5。 |
| --departure-token | 否 | — | 为特定去程航班获取返程航班(高级用法,很少直接需要) |
| --booking-token | 否 | — | 使用特定航班的 booking_token 获取预订选项(真实航空公司/OTA 网址) |
目的地代码
Google Flights 接受:
- - 机场代码: LHR、CDG、TLV
- 城市代码: LON(所有伦敦机场)、PAR(所有巴黎机场)、NYC
当用户未指定首选机场时,使用城市代码。
输出格式
脚本将 JSON 输出到标准输出。
单程 / 仅去程
json
{
origin: TLV,
destination: LON,
flighttype: oneway,
daterange: { from: 2026-03-15, to: 2026-03-17, dayssearched: 3 },
currency: USD,
total_results: 24,
showing: 15,
flights: [
{
search_date: 2026-03-15,
airline: El Al,
flight_number: LY315,
origin: TLV,
destination: LHR,
departure_time: 22:00,
departure_date: 2026-03-15,
arrival_time: 01:30,
arrival_date: 2026-03-16,
duration_minutes: 270,
stops: 0,
layovers: [],
minlayoverminutes: null,
price: 1850,
overnight: true,
booking_token: WyJDa...
}
]
}
使用 --top 5 的往返行程(包含返程航班详情)
当 --top N 与 --return-date 一起使用时,前 N 个去程结果中的每一个都包含一个嵌套的 return_flight 对象,其中包含完整的返程航段详情:
json
{
origin: TLV,
destination: BKK,
flighttype: roundtrip,
return_date: 2026-04-14,
returnflightsfetchedfortop: 5,
flights: [
{
search_date: 2026-03-28,
airline: Etihad,
flight_number: EY 610,
origin: TLV,
destination: BKK,
departure_time: 07:20,
departure_date: 2026-03-28,
arrival_time: 23:25,
arrival_date: 2026-03-28,
duration_minutes: 725,
stops: 1,
layovers: [{airport: Zayed International Airport, duration_minutes: 185}],
minlayoverminutes: 185,
price: 1569,
overnight: false,
return_flight: {
airline: Etihad,
flight_number: EY 401,
origin: BKK,
destination: TLV,
departure_time: 01:05,
departure_date: 2026-04-14,
arrival_time: 08:15,
arrival_date: 2026-04-14,
duration_minutes: 670,
stops: 1,
layovers: [{airport: Zayed International Airport, duration_minutes: 150}],
minlayoverminutes: 150,
overnight: false,
price: 1569,
booking_token: EhkIAh...
}
}
]
}
重要提示: price 是往返总价(在去程和返程航班上相同)。return_flight 对象有自己的航空公司、航班号、时间、中转站和经停次数——在格式化结果时使用所有这些信息。
预订令牌查询(--booking-token)
评分后,使用每个顶级结果的 booking_token 获取真实的预订网址。
您必须传递原始搜索中使用的相同 --from、--to、--date。对于往返行程,还需传递 --return-date。
bash
单程预订查询
python {baseDir}/scripts/search_searchapi.py \
--from TLV --to LON --date 2026-03-15 \
--booking-token WyJDa...
往返预订查询 — 必须包含 --return-date
python {baseDir}/scripts/search_searchapi.py \
--from TLV --to SGN --date 2026-03-29 --return-date 2026-04-14 \
--booking-token WyJDa...
返回:
json
{
mode: booking_lookup,
total_options: