diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-11-19 20:53:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-19 20:53:11 +0100 |
commit | de4f374c5d01216cf62ba3594cff3762a1fd8159 (patch) | |
tree | 7dd083571e2396a627dfd468f21af8402cc39f2d /g4f/cookies.py | |
parent | Merge pull request #2382 from hlohaus/info (diff) | |
parent | Add --cookie-browsers argument to cli (diff) | |
download | gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.tar gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.tar.gz gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.tar.bz2 gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.tar.lz gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.tar.xz gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.tar.zst gpt4free-de4f374c5d01216cf62ba3594cff3762a1fd8159.zip |
Diffstat (limited to 'g4f/cookies.py')
-rw-r--r-- | g4f/cookies.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/g4f/cookies.py b/g4f/cookies.py index 8d535ce7..0c62d697 100644 --- a/g4f/cookies.py +++ b/g4f/cookies.py @@ -15,9 +15,32 @@ try: brave, edge, vivaldi, firefox, _LinuxPasswordManager, BrowserCookieError ) + + def _g4f(domain_name: str) -> list: + """ + Load cookies from the 'g4f' browser (if exists). + + Args: + domain_name (str): The domain for which to load cookies. + + Returns: + list: List of cookies. + """ + if not has_platformdirs: + return [] + user_data_dir = user_config_dir("g4f") + cookie_file = os.path.join(user_data_dir, "Default", "Cookies") + return [] if not os.path.exists(cookie_file) else chrome(cookie_file, domain_name) + + browsers = [ + _g4f, + chrome, chromium, opera, opera_gx, + brave, edge, vivaldi, firefox, + ] has_browser_cookie3 = True except ImportError: has_browser_cookie3 = False + browsers = [] from .typing import Dict, Cookies from .errors import MissingRequirementsError @@ -114,7 +137,7 @@ def read_cookie_files(dirPath: str = None): harFiles = [] cookieFiles = [] - for root, dirs, files in os.walk(CookiesConfig.cookies_dir if dirPath is None else dirPath): + for root, _, files in os.walk(CookiesConfig.cookies_dir if dirPath is None else dirPath): for file in files: if file.endswith(".har"): harFiles.append(os.path.join(root, file)) |