-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (49 loc) · 1.65 KB
/
main.py
File metadata and controls
55 lines (49 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""RunIt entry point: exposes OpenSky's SearchEngine as a deployable function."""
import sys
import os
# Add src/ to path so opensky package is importable
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
from opensky.search import SearchEngine
def search_flights(
origin: str = "BER",
destination: str = "LHR",
date: str = "2026-04-01",
currency: str = "EUR",
max_price: float = 500.0,
) -> dict:
"""Search flights between airports. Uses real airline data, no API keys needed."""
engine = SearchEngine(currency=currency)
try:
results = engine.search_scored(
origin.upper(),
destination.upper(),
date,
max_price=max_price,
)
flights = []
for sf in results:
f = sf.flight
flight = {
"origin": sf.origin,
"destination": sf.destination,
"date": sf.date,
"route": sf.route,
"price": f.price,
"currency": f.currency,
"stops": f.stops,
"duration_minutes": f.duration_minutes,
"provider": f.provider,
"risk_level": sf.risk.risk_level.value,
}
if f.booking_url:
flight["booking_url"] = f.booking_url
flights.append(flight)
return {
"route": f"{origin.upper()} -> {destination.upper()}",
"date": date,
"currency": currency,
"total_results": len(flights),
"flights": sorted(flights, key=lambda x: x["price"]),
}
finally:
engine.close()