|
16 | 16 | class BARD(Provider): |
17 | 17 | def __init__( |
18 | 18 | self, |
19 | | - auth: str, |
| 19 | + cookie_file: str, |
20 | 20 | proxy: dict = {}, |
21 | 21 | timeout: int = 30, |
22 | 22 | ): |
23 | 23 | """Initializes BARD |
24 | 24 |
|
25 | 25 | Args: |
26 | | - auth (str): `__Secure-1PSID` cookie value (session id) or path to `bard.google.com.cookies.json` file |
| 26 | + cookie_file (str): Path to `bard.google.com.cookies.json` file |
27 | 27 | proxy (dict, optional): Http request proxy. Defaults to {}. |
28 | 28 | timeout (int, optional): Http request timeout. Defaults to 30. |
29 | 29 | """ |
30 | 30 | self.conversation = Conversation(False) |
31 | | - self.session_auth = None |
32 | | - assert isinstance(auth, str), f"auth should be of {str} only not '{type(auth)}'" |
33 | | - if path.isfile(auth): |
| 31 | + self.session_auth1 = None |
| 32 | + self.session_auth2 = None |
| 33 | + assert isinstance(cookie_file, str), f"cookie_file should be of {str} only not '{type(cookie_file)}'" |
| 34 | + if path.isfile(cookie_file): |
34 | 35 | # let's assume auth is a path to exported .json cookie-file |
35 | | - with open(auth) as fh: |
| 36 | + with open(cookie_file) as fh: |
36 | 37 | entries = load(fh) |
37 | 38 | for entry in entries: |
38 | 39 | if entry["name"] == "__Secure-1PSID": |
39 | | - self.session_auth = entry["value"] |
40 | | - assert bool( |
41 | | - self.session_auth |
42 | | - ), f"Failed to extract the required cookie value from file '{auth}'" |
| 40 | + self.session_auth1 = entry["value"] |
| 41 | + elif entry['name']=="__Secure-1PAPISID": |
| 42 | + self.session_auth2 = entry["value"] |
| 43 | + |
| 44 | + assert all( |
| 45 | + [ |
| 46 | + self.session_auth1, self.session_auth2 |
| 47 | + ] |
| 48 | + ), f"Failed to extract the required cookie value from file '{cookie_file}'" |
43 | 49 | else: |
44 | | - # Assume auth is the targeted cookie value |
45 | | - self.session_auth = auth |
46 | | - |
47 | | - self.session = Chatbot(self.session_auth, proxy, timeout) |
| 50 | + raise Exception(f'{cookie_file} is not a valid file path') |
| 51 | + |
| 52 | + self.session = Chatbot(self.session_auth1,self.session_auth2, proxy, timeout) |
48 | 53 | self.last_response = {} |
49 | 54 | self.__available_optimizers = ( |
50 | 55 | method |
|
0 commit comments