Hansimov commited on
Commit
b2e11d6
1 Parent(s): 70c1e23

:zap: [Enhance] Enable create with new cookie item KievRPSSecAuth

Browse files
apis/chat_api.py CHANGED
@@ -145,6 +145,7 @@ class ChatAPIApp:
145
  sec_access_token=creator.sec_access_token,
146
  client_id=creator.client_id,
147
  conversation_id=creator.conversation_id,
 
148
  invocation_id=0,
149
  )
150
 
 
145
  sec_access_token=creator.sec_access_token,
146
  client_id=creator.client_id,
147
  conversation_id=creator.conversation_id,
148
+ cookies=creator.request_cookies,
149
  invocation_id=0,
150
  )
151
 
networks/cookies_constructor.py CHANGED
@@ -1,8 +1,10 @@
1
  import json
2
  import requests
 
 
 
3
  from datetime import datetime
4
  from pathlib import Path
5
-
6
  from utils.logger import logger
7
 
8
 
@@ -14,6 +16,10 @@ class CookiesConstructor:
14
  self.secrets_path = Path(__file__).parents[1] / "secrets.json"
15
  self.created_datetime_format = "%Y-%m-%d %H:%M:%S"
16
 
 
 
 
 
17
  def create_secrets_json(self):
18
  if not self.secrets_path.exists():
19
  self.secrets_path.parent.mkdir(parents=True, exist_ok=True)
@@ -54,6 +60,7 @@ class CookiesConstructor:
54
 
55
  requests_body = {"cookies": ""}
56
  try:
 
57
  res = requests.post(
58
  self.bypass_url,
59
  json=requests_body,
@@ -61,7 +68,9 @@ class CookiesConstructor:
61
  )
62
  data = res.json()
63
  cookies_str = data["result"]["cookies"]
64
- cookies_snapshot = data["result"]["snapshot"]
 
 
65
  logger.note(f"Get Cookies: {cookies_str}")
66
  if cookies_str:
67
  with open(self.secrets_path, "r") as rf:
@@ -71,7 +80,7 @@ class CookiesConstructor:
71
  "created_time": datetime.now().strftime(
72
  self.created_datetime_format
73
  ),
74
- "snapshot": self.bypass_url + cookies_snapshot,
75
  }
76
  with open(self.secrets_path, "w") as wf:
77
  json.dump(secrets, wf)
 
1
  import json
2
  import requests
3
+ import random
4
+ import string
5
+
6
  from datetime import datetime
7
  from pathlib import Path
 
8
  from utils.logger import logger
9
 
10
 
 
16
  self.secrets_path = Path(__file__).parents[1] / "secrets.json"
17
  self.created_datetime_format = "%Y-%m-%d %H:%M:%S"
18
 
19
+ def generate_kiev_rps_sec_auth(self):
20
+ kiev = "".join(random.choices(string.ascii_uppercase + string.digits, k=32))
21
+ return kiev
22
+
23
  def create_secrets_json(self):
24
  if not self.secrets_path.exists():
25
  self.secrets_path.parent.mkdir(parents=True, exist_ok=True)
 
60
 
61
  requests_body = {"cookies": ""}
62
  try:
63
+ logger.note(f"Requesting Cookies from: {self.bypass_url}")
64
  res = requests.post(
65
  self.bypass_url,
66
  json=requests_body,
 
68
  )
69
  data = res.json()
70
  cookies_str = data["result"]["cookies"]
71
+ cookies_screenshot = data["result"]["screenshot"]
72
+ kiev = self.generate_kiev_rps_sec_auth()
73
+ cookies_str = f"KievRPSSecAuth={kiev}; {cookies_str}"
74
  logger.note(f"Get Cookies: {cookies_str}")
75
  if cookies_str:
76
  with open(self.secrets_path, "r") as rf:
 
80
  "created_time": datetime.now().strftime(
81
  self.created_datetime_format
82
  ),
83
+ "screenshot": self.bypass_url + cookies_screenshot,
84
  }
85
  with open(self.secrets_path, "w") as wf:
86
  json.dump(secrets, wf)