From 17000a11fad3b17f5de2a143111f34b8dec407da Mon Sep 17 00:00:00 2001 From: Andrea Iorio Date: Mon, 24 Feb 2025 23:15:38 +0000 Subject: [PATCH 1/3] Update core.py --- fast_flights/core.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/fast_flights/core.py b/fast_flights/core.py index e26d133d..40ebbe4f 100644 --- a/fast_flights/core.py +++ b/fast_flights/core.py @@ -9,8 +9,9 @@ from .primp import Client, Response -def fetch(params: dict) -> Response: - client = Client(impersonate="chrome_126", verify=False) +def fetch(params: dict, timeout: int = 30) -> Response: + timeout = params.get("timeout", timeout) + client = Client(impersonate="chrome_126", verify=False, timeout=timeout) res = client.get("https://www.google.com/travel/flights", params=params) assert res.status_code == 200, f"{res.status_code} Result: {res.text_markdown}" return res @@ -21,6 +22,7 @@ def get_flights_from_filter( currency: str = "", *, mode: Literal["common", "fallback", "force-fallback"] = "common", + timeout: int = 30, ) -> Result: data = filter.as_b64() @@ -33,21 +35,20 @@ def get_flights_from_filter( if mode in {"common", "fallback"}: try: - res = fetch(params) + res = fetch(params, timeout) except AssertionError as e: if mode == "fallback": - res = fallback_playwright_fetch(params) + res = fallback_playwright_fetch(params, timeout) else: raise e - else: - res = fallback_playwright_fetch(params) + res = fallback_playwright_fetch(params, timeout) try: return parse_response(res) except RuntimeError as e: if mode == "fallback": - return get_flights_from_filter(filter, mode="force-fallback") + return get_flights_from_filter(filter, mode="force-fallback", timeout=timeout) raise e @@ -59,6 +60,7 @@ def get_flights( seat: Literal["economy", "premium-economy", "business", "first"], fetch_mode: Literal["common", "fallback", "force-fallback"] = "common", max_stops: Optional[int] = None, + timeout: Optional[int] = 30, ) -> Result: return get_flights_from_filter( TFSData.from_interface( @@ -69,6 +71,7 @@ def get_flights( max_stops=max_stops, ), mode=fetch_mode, + timeout=timeout, ) From 68c91b95c093d4b5436c847070fbe07b442a985a Mon Sep 17 00:00:00 2001 From: Andrea Iorio Date: Mon, 24 Feb 2025 23:16:13 +0000 Subject: [PATCH 2/3] Update fallback_playwright.py --- fast_flights/fallback_playwright.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fast_flights/fallback_playwright.py b/fast_flights/fallback_playwright.py index a2a26bc9..3a778d47 100644 --- a/fast_flights/fallback_playwright.py +++ b/fast_flights/fallback_playwright.py @@ -26,8 +26,8 @@ async def main(): """ -def fallback_playwright_fetch(params: dict) -> Any: - client = Client(impersonate="chrome_100", verify=False) +def fallback_playwright_fetch(params: dict, timeout: int = 30) -> Any: + client = Client(impersonate="chrome_100", verify=False, timeout=timeout) res = client.post( "https://try.playwright.tech/service/control/run", From ae45558f97b4cc512b0991d3a8772bee94c77486 Mon Sep 17 00:00:00 2001 From: Andrea Iorio Date: Tue, 25 Feb 2025 21:29:41 +0000 Subject: [PATCH 3/3] Update core.py --- fast_flights/core.py | 1 - 1 file changed, 1 deletion(-) diff --git a/fast_flights/core.py b/fast_flights/core.py index 40ebbe4f..2126ae1b 100644 --- a/fast_flights/core.py +++ b/fast_flights/core.py @@ -10,7 +10,6 @@ def fetch(params: dict, timeout: int = 30) -> Response: - timeout = params.get("timeout", timeout) client = Client(impersonate="chrome_126", verify=False, timeout=timeout) res = client.get("https://www.google.com/travel/flights", params=params) assert res.status_code == 200, f"{res.status_code} Result: {res.text_markdown}"