diff options
author | t.me/xtekky <98614666+xtekky@users.noreply.github.com> | 2023-06-24 03:47:00 +0200 |
---|---|---|
committer | t.me/xtekky <98614666+xtekky@users.noreply.github.com> | 2023-06-24 03:47:00 +0200 |
commit | 5db58fd87f230fbe5bae599bb4b120ab42cad3be (patch) | |
tree | 770be13bca77c5d04dfe3265f378431df788706f /g4f/utils.py | |
parent | Merge pull request #664 from LopeKinz/main (diff) | |
download | gpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.tar gpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.tar.gz gpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.tar.bz2 gpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.tar.lz gpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.tar.xz gpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.tar.zst gpt4free-5db58fd87f230fbe5bae599bb4b120ab42cad3be.zip |
Diffstat (limited to 'g4f/utils.py')
-rw-r--r-- | g4f/utils.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/g4f/utils.py b/g4f/utils.py new file mode 100644 index 00000000..d5ab41c7 --- /dev/null +++ b/g4f/utils.py @@ -0,0 +1,49 @@ +import browser_cookie3 + + +class Utils: + browsers = [ + browser_cookie3.chrome, # 62.74% market share + browser_cookie3.safari, # 24.12% market share + browser_cookie3.firefox, # 4.56% market share + browser_cookie3.edge, # 2.85% market share + browser_cookie3.opera, # 1.69% market share + browser_cookie3.brave, # 0.96% market share + browser_cookie3.opera_gx, # 0.64% market share + browser_cookie3.vivaldi, # 0.32% market share + ] + + def get_cookies(domain: str, setName: str = None, setBrowser: str = False) -> dict: + cookies = {} + + if setBrowser != False: + for browser in Utils.browsers: + if browser.__name__ == setBrowser: + try: + for c in browser(domain_name=domain): + if c.name not in cookies: + cookies = cookies | {c.name: c.value} + + except Exception as e: + pass + + else: + for browser in Utils.browsers: + try: + for c in browser(domain_name=domain): + if c.name not in cookies: + cookies = cookies | {c.name: c.value} + + except Exception as e: + pass + + if setName: + try: + return {setName: cookies[setName]} + + except ValueError: + print(f'Error: could not find {setName} cookie in any browser.') + exit(1) + + else: + return cookies |