Antonio Cheong commited on
Commit
9bf779e
·
1 Parent(s): b25c140

Use cookie files

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. src/EdgeGPT.py +11 -49
.gitignore CHANGED
@@ -127,3 +127,4 @@ dmypy.json
127
 
128
  # Pyre type checker
129
  .pyre/
 
 
127
 
128
  # Pyre type checker
129
  .pyre/
130
+ cookies.json
src/EdgeGPT.py CHANGED
@@ -4,10 +4,9 @@ Main.py
4
  import argparse
5
  import asyncio
6
  import json
7
- import os
8
  import sys
 
9
 
10
- import requests
11
  import tls_client
12
  import websockets.client as websockets
13
 
@@ -106,51 +105,15 @@ class Conversation:
106
  "result": {"value": "Success", "message": None},
107
  }
108
  self.session = tls_client.Session(client_identifier="chrome_108")
109
- # POST request to get token
110
- # Create cookies
111
- # if os.environ.get("BING_U") is None:
112
- # home = os.path.expanduser("~")
113
- # # Check if token exists
114
- # token_path = f"{home}/.config/bing_token"
115
- # # Make .config directory if it doesn't exist
116
- # if not os.path.exists(f"{home}/.config"):
117
- # os.mkdir(f"{home}/.config")
118
- # if os.path.exists(token_path):
119
- # with open(token_path, "r", encoding="utf-8") as file:
120
- # token = file.read()
121
- # else:
122
- # url = "https://images.duti.tech/allow"
123
- # response = requests.post(
124
- # url,
125
- # timeout=10,
126
- # headers=headers,
127
- # )
128
- # if response.status_code != 200:
129
- # raise Exception("Authentication failed")
130
- # token = response.json()["token"]
131
- # # Save token
132
- # with open(token_path, "w", encoding="utf-8") as file:
133
- # file.write(token)
134
- # url = "https://images.duti.tech/auth"
135
- # # Send GET request
136
- # response = requests.get(
137
- # url,
138
- # headers=headers,
139
- # timeout=10,
140
- # )
141
- # if response.status_code != 200:
142
- # raise Exception("Authentication failed")
143
-
144
- # else:
145
- cookies = {
146
- "_U": os.environ.get("BING_U"),
147
- "KievRPSSecAuth": os.environ.get("KIEV_U"),
148
- }
149
  url = "https://www.bing.com/turing/conversation/create"
150
  # Send GET request
151
  response = self.session.get(
152
  url,
153
- cookies=cookies,
154
  timeout_seconds=30,
155
  headers=headers,
156
  )
@@ -351,11 +314,10 @@ if __name__ == "__main__":
351
  )
352
  parser = argparse.ArgumentParser()
353
  parser.add_argument("--no-stream", action="store_true")
354
- parser.add_argument("--bing-cookie", type=str, default="", required=True)
355
- parser.add_argument("--kiev-cookie", type=str, default="", required=False)
 
 
 
356
  args = parser.parse_args()
357
- if args.bing_cookie:
358
- os.environ["BING_U"] = args.bing_cookie
359
- if args.kiev_cookie:
360
- os.environ["KIEV_U"] = args.kiev_cookie
361
  asyncio.run(main())
 
4
  import argparse
5
  import asyncio
6
  import json
 
7
  import sys
8
+ import os
9
 
 
10
  import tls_client
11
  import websockets.client as websockets
12
 
 
105
  "result": {"value": "Success", "message": None},
106
  }
107
  self.session = tls_client.Session(client_identifier="chrome_108")
108
+ cookie_file = json.loads(
109
+ open(os.environ.get("COOKIE_FILE"), "r", encoding="utf-8").read()
110
+ )
111
+ for cookie in cookie_file:
112
+ self.session.cookies.set(cookie["name"], cookie["value"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  url = "https://www.bing.com/turing/conversation/create"
114
  # Send GET request
115
  response = self.session.get(
116
  url,
 
117
  timeout_seconds=30,
118
  headers=headers,
119
  )
 
314
  )
315
  parser = argparse.ArgumentParser()
316
  parser.add_argument("--no-stream", action="store_true")
317
+ parser.add_argument(
318
+ "--cookie-file", type=str, default="cookies.json", required=True
319
+ )
320
+ args = parser.parse_args()
321
+ os.environ["COOKIE_FILE"] = args.cookie_file
322
  args = parser.parse_args()
 
 
 
 
323
  asyncio.run(main())