From 1fe59623b22790dc2db36f106112795859bc6a25 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Tue, 19 Nov 2024 20:26:00 +0100 Subject: Add image upload to Copilot provider Add --cookie-browsers argument to cli --- g4f/cookies.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'g4f/cookies.py') diff --git a/g4f/cookies.py b/g4f/cookies.py index 8d535ce7..a43ccc86 100644 --- a/g4f/cookies.py +++ b/g4f/cookies.py @@ -15,6 +15,28 @@ 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 @@ -114,7 +136,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)) -- cgit v1.2.3 From 275404373f73cbae7835590c66dbe230155d77f9 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Tue, 19 Nov 2024 20:45:25 +0100 Subject: Add --cookie-browsers argument to cli --- g4f/cookies.py | 1 + 1 file changed, 1 insertion(+) (limited to 'g4f/cookies.py') diff --git a/g4f/cookies.py b/g4f/cookies.py index a43ccc86..0c62d697 100644 --- a/g4f/cookies.py +++ b/g4f/cookies.py @@ -40,6 +40,7 @@ try: has_browser_cookie3 = True except ImportError: has_browser_cookie3 = False + browsers = [] from .typing import Dict, Cookies from .errors import MissingRequirementsError -- cgit v1.2.3