Files
Gov_Travel_App/documents/FLIGHT_API_COMPLETE.md
mblanke 15094ac94b Add Python web scraper for NJC travel rates with currency extraction
- Implemented Python scraper using BeautifulSoup and pandas to automatically collect travel rates from official NJC website
- Added currency extraction from table titles (supports EUR, USD, AUD, CAD, ARS, etc.)
- Added country extraction from table titles for international rates
- Flatten pandas MultiIndex columns for cleaner data structure
- Default to CAD for domestic Canadian sources (accommodations and domestic tables)
- Created SQLite database schema (raw_tables, rate_entries, exchange_rates, accommodations)
- Successfully scraped 92 tables with 17,205 rate entries covering 25 international cities
- Added migration script to convert scraped data to Node.js database format
- Updated .gitignore for Python files (.venv/, __pycache__, *.pyc, *.sqlite3)
- Fixed city validation and currency conversion in main app
- Added comprehensive debug and verification scripts

This replaces manual JSON maintenance with automated data collection from official government source.
2026-01-13 09:21:43 -05:00

8.0 KiB
Raw Blame History

🎉 Automatic Flight Search Integration Complete!

What's New

Your Government Travel Cost Estimator now has automatic flight search using the Amadeus Flight API!

New Features

  1. 🔍 Automatic Flight Search

    • Click "Search Flights Automatically" button
    • App fetches real flight prices in seconds
    • No manual entry needed
  2. 💰 Real-Time Pricing

    • Official airline data
    • Prices in CAD
    • Shows 5 cheapest options
  3. ⏱️ Automatic Duration Calculation

    • Calculates flight hours automatically
    • Business class eligibility detected (≥9 hours)
    • No manual duration entry
  4. 🎫 Multiple Flight Options

    • Compare 5 cheapest flights
    • See stops, duration, and carrier
    • Click to select any flight

🚀 How to Use

Setup Required: 5 minutes one-time setup See: AMADEUS_SETUP.md for detailed instructions

  1. Register at https://developers.amadeus.com/register
  2. Create an app and get API credentials
  3. Add credentials to .env file:
    AMADEUS_API_KEY=your_key_here
    AMADEUS_API_SECRET=your_secret_here
    
  4. Restart the server

Benefits:

  • 5 seconds per search
  • Automatic duration and business class detection
  • 💯 Real-time official pricing
  • 🎯 Compare multiple options instantly

Option 2: Without API (Manual)

No setup required - works immediately!

  1. Enter departure/destination cities
  2. App shows Google Flights link
  3. Click link, copy price
  4. Enter duration manually
  5. Continue with estimate

Benefits:

  • 🚀 Zero setup time
  • 💰 No API account needed
  • ⏱️ Takes ~30 seconds per search

📂 New Files

File Purpose
flightService.js Flight API integration logic
AMADEUS_SETUP.md Complete setup guide with screenshots
.env.example Template for API credentials
.env Your actual credentials (gitignored)

🔧 Quick Start

Run Locally

# Install dependencies (if not done)
npm install

# Start server
npm start

Access at: http://localhost:5001

Run with Docker

# Build image
docker build -t govt-travel-app:latest .

# Run container
docker run -d -p 5001:5001 --name govt-travel-estimator govt-travel-app:latest

Access at: http://localhost:5001


⚙️ Configuration Status

When you start the server, you'll see one of these messages:

API Configured

✅ Amadeus API configured

Status: Automatic flight search enabled!

⚠️ API Not Configured

⚠️ WARNING: Amadeus API credentials not configured!
   Get free API key at: https://developers.amadeus.com/register

Status: Manual Google Flights fallback available


Step 1: Enter Trip Details

  • Departure City: Ottawa
  • Destination City: Vancouver
  • Departure Date: 2025-11-15
  • Return Date: 2025-11-18
  • Transport Mode: Flight

Step 2: Click "Search Flights Automatically"

The app:

  1. Converts city names to airport codes (YOW → YVR)
  2. Queries Amadeus API for flights
  3. Returns 5 cheapest round-trip options
  4. Calculates duration for each flight
  5. Flags flights ≥9 hours for business class

Step 3: Review Results

Example output:

✅ Found 5 flight options

$650.00 CAD  [Business Class Eligible]
Duration: 9.2 hours | Direct
[Select Button]

$620.00 CAD
Duration: 7.5 hours | 1 stop(s)
[Select Button]

Step 4: Select Flight

Click any flight:

  • Price and duration auto-populate
  • Business class note shown if applicable
  • Scroll to accommodation section
  • Complete your estimate

💡 API Limits (Free Tier)

  • 2,000 API calls/month
  • ~66 searches per day
  • Perfect for small teams
  • No credit card required

🌍 Supported Routes

The app knows airport codes for 60+ cities:

Canadian Cities (16)

Ottawa (YOW), Toronto (YYZ), Montreal (YUL), Vancouver (YVR), Calgary (YYC), Edmonton (YEG), Winnipeg (YWG), Halifax (YHZ), Victoria (YYJ), Quebec City (YQB), Regina (YQR), Saskatoon (YXE), Thunder Bay (YQT), Whitehorse (YXY), Yellowknife (YZF), Iqaluit (YFB)

US Cities (15)

New York (JFK), Los Angeles (LAX), Chicago (ORD), San Francisco (SFO), Seattle (SEA), Boston (BOS), Washington DC (IAD), Miami (MIA), Atlanta (ATL), Dallas (DFW), Denver (DEN), Phoenix (PHX), Las Vegas (LAS), Orlando (MCO), Anchorage (ANC)

International (30+)

London, Paris, Frankfurt, Amsterdam, Rome, Madrid, Tokyo, Beijing, Hong Kong, Singapore, Dubai, Sydney, Melbourne, Auckland, Mexico City, São Paulo, Buenos Aires, and more...


🎨 User Interface Changes

Before (Manual Entry)

[ Flight Duration (hours) * ]
[ Estimated Flight Cost (CAD) ]
💡 Search Google Flights for prices
[🔍 Search Flights Automatically] ← Click this!

✅ Found 5 flight options

$650 CAD | 9.2 hours | Direct [Select]
$620 CAD | 7.5 hours | 1 stop [Select]
...

✅ Flight Selected
Price: $650 CAD | Duration: 9.2 hours | ⚠️ Business class eligible

🔐 Security

  • API credentials stored in .env (gitignored)
  • Server-side API calls only
  • No credentials exposed to browser
  • HTTPS connections to Amadeus

📊 Example Calculation

Trip: Ottawa → London (9.5 hour flight)

Automatic Search Results:

Flight: $1,200 CAD (economy)
Duration: 9.5 hours
Business Class: Eligible (≥9 hours)

App Calculation:

✈️  Flight Cost: $3,000.00
    Business class applicable (flight 9.5 hours ≥ 9 hours)
    Estimated at 2.5x economy cost per NJC Directive

🏨 Accommodation: $960.00 (3 nights × $320/night)
🍽️  Meals: $477.60 (4 days × $119.40/day)
💰 Incidentals: $80.00 (4 days × $20/day)
────────────────────────────────────
Total: $4,517.60 CAD

🆘 Troubleshooting

"Flight API not configured"

Solution: Follow AMADEUS_SETUP.md to get free API credentials

"Could not find airport codes"

Solution: City name format matters:

  • "Ottawa"
  • "New York"
  • "Ottawa, ON"
  • "NYC"

"No flights found"

Possible causes:

  1. Date too far in future (try within 11 months)
  2. Small airports without commercial flights
  3. Route not served by airlines
  4. Try manual Google Flights fallback

Server won't start

Check:

# View logs
docker logs govt-travel-estimator

# Or run locally
npm start

🎓 Documentation

File Description
AMADEUS_SETUP.md Complete API setup guide
README.md Main application docs
DATABASE_UPDATE_GUIDE.md How to update rates
DEPLOYMENT.md Docker deployment guide

🚀 Next Steps

  1. Get API Access (5 min)

    • Follow AMADEUS_SETUP.md
    • Add credentials to .env
    • Restart server
  2. Test Flight Search

    • Enter Ottawa → Vancouver
    • Click "Search Flights"
    • Select a flight
    • Complete estimate
  3. Share with Team

    • Everyone uses same app
    • Share API key (internal only)
    • Track usage at Amadeus dashboard

📈 Comparison

Feature Before After
Flight pricing Manual Google search Automatic API
Duration entry Manual typing Auto-calculated
Business class detection Manual check Auto-flagged
Speed ~60 seconds ~10 seconds
Accuracy User-dependent Official data
Multiple options One at a time 5 instantly

Summary

You now have a fully automated travel cost estimator that:

  • Searches real flight prices automatically
  • Calculates business class eligibility
  • Shows multiple flight options
  • Works with or without API setup
  • Saves tons of time

With API: Ultra-fast, automatic, real-time pricing
Without API: Still works great with Google Flights fallback


Enjoy your new automatic flight search! 🎉✈️

Questions? See AMADEUS_SETUP.md for detailed setup instructions.