Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions fast_flights/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ def safe(n: Optional[LexborNode]):
name = safe(item.css_first("div.sSHqwe.tPgKwe.ogfYpf span")).text(
strip=True
)
# from_airport - to_airport
from_to_airport_node = item.css("span.PTuQse.sSHqwe.tPgKwe.ogfYpf div.QylvBf span span span")
try:
from_airport = from_to_airport_node[0].text(strip=True)
to_airport = from_to_airport_node[1].text(strip=True)
except IndexError:
from_airport = ""
to_airport = ""

# Get departure & arrival time
dp_ar_node = item.css("span.mv1WYe div")
Expand Down Expand Up @@ -141,6 +149,8 @@ def safe(n: Optional[LexborNode]):
{
"is_best": is_best_flight,
"name": name,
"from_airport": from_airport,
"to_airport": to_airport,
"departure": " ".join(departure_time.split()),
"arrival": " ".join(arrival_time.split()),
"arrival_time_ahead": time_ahead,
Expand Down
5 changes: 3 additions & 2 deletions fast_flights/flights.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ message Airport {

message FlightData {
string date = 2;
Airport from_flight = 13;
Airport to_flight = 14;
repeated string airlines = 6;
repeated Airport from_flight = 13;
repeated Airport to_flight = 14;
optional int32 max_stops = 5;
}

Expand Down
18 changes: 13 additions & 5 deletions fast_flights/flights_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ class FlightData:
date (str): Date.
from_airport (str): Departure (airport). Where from?
to_airport (str): Arrival (airport). Where to?
airlines (list(str), optional): A list of airlines. Default is None.
max_stops (int, optional): Maximum number of stops. Default is None.
"""

__slots__ = ("date", "from_airport", "to_airport", "max_stops")
__slots__ = ("date", "from_airport", "to_airport", "airlines", "max_stops")
date: str
from_airport: str
to_airport: str
airlines: Optional[List[str]]
max_stops: Optional[int]

def __init__(
Expand All @@ -32,22 +34,28 @@ def __init__(
date: str,
from_airport: Union[Airport, str],
to_airport: Union[Airport, str],
airlines: Optional[List[str]] = None,
max_stops: Optional[int] = None,
):
self.date = date
self.from_airport = (
from_airport.value if isinstance(from_airport, Airport) else from_airport
)
).split(',')
self.to_airport = (
to_airport.value if isinstance(to_airport, Airport) else to_airport
)
).split(',')
self.airlines = airlines
self.max_stops = max_stops

def attach(self, info: PB.Info) -> None: # type: ignore
data = info.data.add()
data.date = self.date
data.from_flight.airport = self.from_airport
data.to_flight.airport = self.to_airport
for from_airport in self.from_airport:
data.from_flight.add().airport = from_airport
for to_airport in self.to_airport:
data.to_flight.add().airport = to_airport
if self.airlines is not None:
data.airlines[:] = self.airlines
if self.max_stops is not None:
data.max_stops = self.max_stops

Expand Down
49 changes: 30 additions & 19 deletions fast_flights/flights_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions fast_flights/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Result:
class Flight:
is_best: bool
name: str
from_airport: str
to_airport: str
departure: str
arrival: str
arrival_time_ahead: str
Expand Down