Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Commit

Permalink
dashes in environmental vars cause problems, so i got rid of them (#73)
Browse files Browse the repository at this point in the history
* compatibility: got rid of dashes in environment vars

* reflect latest changes in readme and documentation

* reverted cookie-names in readme

* more consistency in the readme
  • Loading branch information
jans-code authored Jul 20, 2023
1 parent 1ad3f1d commit dbc06dd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
6 changes: 4 additions & 2 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class AsyncChatbot()

A class to interact with Google Bard.
Parameters
session_id: str
The __Secure-1PSID cookie.
session: str
The __Secure_1PSID cookie.
session_ts: str
The __Secure_1PSIDTS cookie
proxy: str
timeout: int
Request timeout in seconds.
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ Go to https://bard.google.com/

```bash
$ python3 -m Bard -h
usage: Bard.py [-h] --session SESSION
usage: Bard.py [-h] --session <__Secure-1PSID> --session_ts <__Secure-1PSIDTS>

options:
-h, --help show this help message and exit
--__Secure_1PSID --__Secure_1PSIDTS pass two cookies
--session --session_ts pass two cookies
```

### Quick mode
```
$ export BARD_QUICK="true"
$ export BARD___Secure-1PSID="<__Secure-1PSID>"
$ export BARD___Secure-1PSIDTS="<__Secure-1PSIDTS>"
$ export BARD__Secure_1PSID="<__Secure-1PSID>"
$ export BARD__Secure_1PSIDTS="<__Secure-1PSIDTS>"
$ python3 -m Bard
```
Environment variables can be placed in .zshrc.
Expand All @@ -39,8 +39,8 @@ Example bash shortcut:
# USAGE2: echo "QUESTION" | bard
bard () {
export BARD_QUICK=true
export BARD___Secure-1PSID==<REDACTED>.
export BARD___Secure-1PSIDTS==<REDACTED>.
export BARD__Secure_1PSID=<__Secure-1PSID>
export BARD__Secure_1PSIDTS=<__Secure-1PSIDTS>
python3 -m Bard "${@:-$(</dev/stdin)}" | tail -n+7
}
```
Expand All @@ -50,8 +50,8 @@ bard () {
from os import environ
from Bard import Chatbot

Secure_1PSID = environ.get("BARD__Secure-1PSID")
Secure_1PSIDTS = environ.get("BARD__Secure-1PSIDTS")
Secure_1PSID = environ.get("BARD__Secure_1PSID")
Secure_1PSIDTS = environ.get("BARD__Secure_1PSIDTS")
chatbot = Chatbot(Secure_1PSID, Secure_1PSIDTS)

chatbot.ask("Hello, how are you?")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="GoogleBard",
version="2.0.0",
version="2.1.1",
license="MIT License",
author="Antonio Cheong",
author_email="[email protected]",
Expand Down
16 changes: 9 additions & 7 deletions src/Bard.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ class AsyncChatbot:
"""
A class to interact with Google Bard.
Parameters
session_id: str
The __Secure-1PSID cookie.
session: str
The __Secure_1PSID cookie.
session_ts: str
The __Secure_1PSIDTS cookie.
proxy: str
timeout: int
Request timeout in seconds.
Expand Down Expand Up @@ -223,7 +225,7 @@ async def __get_snlm0e(self):
or self.secure_1psid[-1] != "."
):
raise Exception(
"Enter correct __Secure-1PSID and __Secure-1PSIDTS value. __Secure-1PSID value must end with a single dot. ",
"Enter correct __Secure_1PSID and __Secure_1PSIDTS value. __Secure_1PSID value must end with a single dot. ",
)
resp = await self.session.get(
"https://bard.google.com/",
Expand All @@ -237,7 +239,7 @@ async def __get_snlm0e(self):
SNlM0e = re.search(r"SNlM0e\":\"(.*?)\"", resp.text)
if not SNlM0e:
raise Exception(
"SNlM0e value not found in response. Check __Secure-1PSID value.",
"SNlM0e value not found in response. Check __Secure_1PSID value.",
)
return SNlM0e.group(1)

Expand Down Expand Up @@ -307,11 +309,11 @@ async def ask(self, message: str) -> dict:
)
console = Console()
if os.getenv("BARD_QUICK"):
Secure_1PSID = os.getenv("BARD___Secure-1PSID")
Secure_1PSIDTS = os.getenv("BARD__Secure-1PSIDTS")
Secure_1PSID = os.getenv("BARD__Secure_1PSID")
Secure_1PSIDTS = os.getenv("BARD__Secure_1PSIDTS")
if not (Secure_1PSID and Secure_1PSIDTS):
print(
"BARD___Secure-1PSID or BARD__Secure-1PSIDTS environment variable not set.",
"BARD__Secure_1PSID or BARD__Secure_1PSIDTS environment variable not set.",
)
sys.exit(1)
chatbot = Chatbot(Secure_1PSID, Secure_1PSIDTS)
Expand Down

0 comments on commit dbc06dd

Please sign in to comment.