Skip to content

max_stops query parameter addition#11

Merged
AWeirdDev merged 2 commits intoAWeirdDev:mainfrom
d2x:main
Sep 28, 2024
Merged

max_stops query parameter addition#11
AWeirdDev merged 2 commits intoAWeirdDev:mainfrom
d2x:main

Conversation

@d2x
Copy link
Copy Markdown
Contributor

@d2x d2x commented Sep 11, 2024

Added optional ability to specify max_stops for flight data search along with example.py reference usage script.

Acceptable values are 0, 1, 2 or undefined for "all flights".

@AWeirdDev
Copy link
Copy Markdown
Owner

Hey,

My apologies, but I'm on mobile. Could you describe how you made max_stops possible?

Thanks a lot for your awesome work!

AWeirdDev

@d2x
Copy link
Copy Markdown
Contributor Author

d2x commented Sep 25, 2024

My apologies, but I'm on mobile. Could you describe how you made max_stops possible?

Field 5 of the FllightData protocol buffer object accepts an integer for number of stops on each defined flight. The values according to the selectors on the UI (determined after decoding protocol buffers string) are as follows:

  • Undefined = flights with any number of stops
  • 0 = non-stop flights only
  • 1 = one or fewer stops
  • 2 = two or fewer stops

Higher numbers are allowed (15 for example) but don't seem to have any impact.

Implementation was achieved by adding the optional integer for field 5 to the protobuf definition and recompiling:

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

After that, was just adding support for it in your core:

def request_flights(
    tfs: TFSData,
    *,
    max_stops: Optional[int] = None,  # Optionally pass max_stops if needed
    currency: Optional[str] = None,
    language: Optional[str],
    **kwargs: Any,
) -> requests.Response:
    params = {
        "tfs": tfs.as_b64(),
        "hl": language,
        "tfu": "EgQIABABIgA",  # show all flights and prices condition
        "curr": currency,
    }
    if max_stops is not None:
        params["max_stops"] = max_stops  # Handle max_stops in request

As well the filter to fill it for all FlightData objects, if it's supplied:

def create_filter(
    *,
    flight_data: List[FlightData],
    trip: Literal["round-trip", "one-way", "multi-city"],
    passengers: Passengers,
    seat: Literal["economy", "premium-economy", "business", "first"],
    max_stops: Optional[int] = None,  # New argument
) -> TFSData:
    """Create a filter. (``?tfs=``)

    Args:
        flight_data (list[FlightData]): Flight data as a list.
        trip ("one-way" | "round-trip" | "multi-city"): Trip type.
        passengers (Passengers): Passengers.
        seat ("economy" | "premium-economy" | "business" | "first"): Seat.
        max_stops (int, optional): Maximum number of stops. Defaults to None.
    """
    for fd in flight_data:
        fd.max_stops = max_stops

Any other UI options, such as bags, should be trivial to add in similar fashion.

@AWeirdDev AWeirdDev merged commit 07b6858 into AWeirdDev:main Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants