diff --git a/examples/auctions/search_gifts.py b/examples/auctions/search_gifts.py index 5d0a9bd..e0c78df 100644 --- a/examples/auctions/search_gifts.py +++ b/examples/auctions/search_gifts.py @@ -10,8 +10,6 @@ Use next_offset for pagination. import asyncio import json -from pyfragment.utils import get_cookies_from_browser # noqa: F401 - from pyfragment import FragmentClient, GiftsResult SEED = "word1 word2 ... word24" diff --git a/examples/auctions/search_numbers.py b/examples/auctions/search_numbers.py index 2d11c17..9cc40e2 100644 --- a/examples/auctions/search_numbers.py +++ b/examples/auctions/search_numbers.py @@ -9,8 +9,6 @@ Use next_offset_id for pagination. import asyncio import json -from pyfragment.utils import get_cookies_from_browser # noqa: F401 - from pyfragment import FragmentClient, NumbersResult SEED = "word1 word2 ... word24" diff --git a/examples/auctions/search_usernames.py b/examples/auctions/search_usernames.py index 2fc2679..b8c4ce3 100644 --- a/examples/auctions/search_usernames.py +++ b/examples/auctions/search_usernames.py @@ -9,8 +9,6 @@ Use next_offset_id for pagination. import asyncio import json -from pyfragment.utils import get_cookies_from_browser # noqa: F401 - from pyfragment import FragmentClient, UsernamesResult SEED = "word1 word2 ... word24" diff --git a/examples/client/raw_api_call.py b/examples/client/raw_api_call.py index 350e5c7..066e755 100644 --- a/examples/client/raw_api_call.py +++ b/examples/client/raw_api_call.py @@ -11,8 +11,6 @@ Defaults to the Fragment base URL. import asyncio -from pyfragment.utils import get_cookies_from_browser # noqa: F401 - from pyfragment import FragmentClient SEED = "word1 word2 ... word24" diff --git a/examples/client/wallet_info.py b/examples/client/wallet_info.py index 5646c7a..7631288 100644 --- a/examples/client/wallet_info.py +++ b/examples/client/wallet_info.py @@ -7,8 +7,6 @@ wallet_version defaults to "V5R1" — change to "V4R2" for older wallets. import asyncio -from pyfragment.utils import get_cookies_from_browser # noqa: F401 - from pyfragment import FragmentClient SEED = "word1 word2 ... word24" diff --git a/examples/numbers/manage_number.py b/examples/numbers/manage_number.py index fb2160a..b4b9702 100644 --- a/examples/numbers/manage_number.py +++ b/examples/numbers/manage_number.py @@ -8,8 +8,6 @@ Use terminate_sessions() to forcefully end all active Telegram sessions. import asyncio -from pyfragment.utils import get_cookies_from_browser # noqa: F401 - from pyfragment import AnonymousNumberError, FragmentClient SEED = "word1 word2 ... word24" diff --git a/examples/purchase/recharge_ads_balance.py b/examples/purchase/recharge_ads_balance.py index 831d7e1..7dc0162 100644 --- a/examples/purchase/recharge_ads_balance.py +++ b/examples/purchase/recharge_ads_balance.py @@ -7,8 +7,6 @@ Your wallet must satisfy the current minimum TON threshold and transaction cost. import asyncio -from pyfragment.utils import get_cookies_from_browser # noqa: F401 - from pyfragment import ( AdsRechargeResult, ConfigurationError, diff --git a/examples/purchase/run_premium_giveaway.py b/examples/purchase/run_premium_giveaway.py index 418dc33..63526c5 100644 --- a/examples/purchase/run_premium_giveaway.py +++ b/examples/purchase/run_premium_giveaway.py @@ -9,8 +9,6 @@ Channel can be "@channel", "channel", or "https://t.me/channel". import asyncio -from pyfragment.utils import get_cookies_from_browser # noqa: F401 - from pyfragment import ConfigurationError, FragmentClient, UserNotFoundError SEED = "word1 word2 ... word24" diff --git a/examples/purchase/run_stars_giveaway.py b/examples/purchase/run_stars_giveaway.py index 1a02c88..83dfc7a 100644 --- a/examples/purchase/run_stars_giveaway.py +++ b/examples/purchase/run_stars_giveaway.py @@ -9,8 +9,6 @@ Channel can be "@channel", "channel", or "https://t.me/channel". import asyncio -from pyfragment.utils import get_cookies_from_browser # noqa: F401 - from pyfragment import ConfigurationError, FragmentClient, UserNotFoundError SEED = "word1 word2 ... word24" diff --git a/examples/purchase/send_premium.py b/examples/purchase/send_premium.py index e17bba9..dab0d48 100644 --- a/examples/purchase/send_premium.py +++ b/examples/purchase/send_premium.py @@ -9,8 +9,6 @@ Username can be "@username", "username", or "https://t.me/username". import asyncio -from pyfragment.utils import get_cookies_from_browser # noqa: F401 - from pyfragment import ConfigurationError, FragmentClient, UserNotFoundError SEED = "word1 word2 ... word24" diff --git a/examples/purchase/send_stars.py b/examples/purchase/send_stars.py index 7e0ba6e..a155fc5 100644 --- a/examples/purchase/send_stars.py +++ b/examples/purchase/send_stars.py @@ -9,8 +9,6 @@ Username can be "@username", "username", or "https://t.me/username". import asyncio -from pyfragment.utils import get_cookies_from_browser # noqa: F401 - from pyfragment import ConfigurationError, FragmentClient, UserNotFoundError SEED = "word1 word2 ... word24" diff --git a/examples/purchase/topup_ton_balance.py b/examples/purchase/topup_ton_balance.py index 0e5c279..e44731c 100644 --- a/examples/purchase/topup_ton_balance.py +++ b/examples/purchase/topup_ton_balance.py @@ -9,8 +9,6 @@ Your wallet must satisfy the current minimum TON threshold and transaction cost. import asyncio -from pyfragment.utils import get_cookies_from_browser # noqa: F401 - from pyfragment import ( ConfigurationError, FragmentClient, diff --git a/pyfragment/core/cookies.py b/pyfragment/core/cookies.py index 2f680fd..ab31943 100644 --- a/pyfragment/core/cookies.py +++ b/pyfragment/core/cookies.py @@ -7,15 +7,25 @@ from pyfragment.core.constants import FRAGMENT_BASE_URL, FRAGMENT_DOMAIN, REQUIR from pyfragment.exceptions import CookieError from pyfragment.models.cookies import CookieResult +try: + import rookiepy as rookiepy # type: ignore[import-not-found,no-redef] +except Exception: + rookiepy = None + def get_cookies_from_browser(browser: str = "chrome") -> CookieResult: + global rookiepy + key = browser.lower() if key not in SUPPORTED_BROWSERS: supported = ", ".join(sorted(SUPPORTED_BROWSERS)) raise CookieError(CookieError.UNSUPPORTED_BROWSER.format(browser=browser, supported=supported)) try: - import rookiepy # type: ignore[import-not-found] + if rookiepy is None: + import rookiepy as imported_rookiepy # type: ignore[import-not-found] + + rookiepy = imported_rookiepy jar: list[dict[str, Any]] = getattr(rookiepy, key)([FRAGMENT_DOMAIN]) except Exception as exc: diff --git a/pyfragment/exceptions.py b/pyfragment/exceptions.py index c4da3d5..d1337f6 100644 --- a/pyfragment/exceptions.py +++ b/pyfragment/exceptions.py @@ -74,7 +74,7 @@ class UserNotFoundError(FragmentAPIError): class AnonymousNumberError(FragmentAPIError): """Raised for Fragment anonymous number API failures.""" - NOT_OWNED = "Number '{number}' is not linked to your Fragment account, or there are no active sessions to terminate." + NOT_OWNED = "Number '{number}' is not associated with your Fragment account or has no active sessions to terminate." TERMINATE_FAILED = "Failed to terminate sessions for '{number}': {error}"