Skip to content

fix serpapi.py — layovers is dict list, not string list #12

fix serpapi.py — layovers is dict list, not string list

fix serpapi.py — layovers is dict list, not string list #12

Workflow file for this run

name: Flight Monitor
on:
schedule:
- cron: "0 2 * * *" # daily 9AM Vietnam time (UTC+7)
workflow_dispatch: # allow manual run
jobs:
monitor:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Check flights
env:
SERPAPI_KEY: ${{ secrets.SERPAPI_KEY }}
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
run: |
python -m pip install httpx
python -c "
import httpx, os

Check failure on line 25 in .github/workflows/monitor.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/monitor.yml

Invalid workflow file

You have an error in your yaml syntax on line 25
from datetime import date, timedelta
chat_id = os.environ['TELEGRAM_CHAT_ID']
token = os.environ['TELEGRAM_TOKEN']
serpapi = os.environ['SERPAPI_KEY']
# Calculate this Friday
today = date.today()
days_ahead = (4 - today.weekday()) % 7
if days_ahead == 0:
days_ahead = 7
friday = today + timedelta(days=days_ahead)
sunday = friday + timedelta(days=2)
routes = [
('SGN', 'HAN', 'Sài Gòn → Hà Nội'),
('SGN', 'DAD', 'Sài Gòn → Đà Nẵng'),
('SGN', 'PQC', 'Sài Gòn → Phú Quốc'),
('HAN', 'SGN', 'Hà Nội → Sài Gòn'),
]
for dep, arr, label in routes:
params = {
'engine': 'google_flights',
'departure_id': dep,
'arrival_id': arr,
'outbound_date': friday.isoformat(),
'return_date': sunday.isoformat(),
'adults': 1,
'currency': 'VND',
'api_key': serpapi,
}
try:
r = httpx.get(
'https://serpapi.com/search.json',
params=params,
timeout=15
)
data = r.json()
best = data.get('best_flights', [])
prices = [f.get('price', 0) for f in best]
min_price = min(prices) if prices else 'N/A'
if isinstance(min_price, int) and min_price > 0:
min_price = f'{min_price:,} VND'
msg = f'✈️ {label}\n📅 {friday}→{sunday}\n💵 Rẻ nhất: {min_price}'
except Exception as exc:
msg = f'⚠️ {label}: Lỗi - {exc}'
url = f'https://api.telegram.org/bot{token}/sendMessage'
httpx.post(url, json={
'chat_id': chat_id,
'text': msg,
'parse_mode': 'Markdown',
})
"