Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit d509675

Browse files
committed
chore: style black
1 parent 6e2f88b commit d509675

File tree

2 files changed

+25
-30
lines changed

2 files changed

+25
-30
lines changed

bardapi/core.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,25 +167,24 @@ def _set_cookie_refresh_data(self):
167167
"https://bard.google.com/", timeout=self.timeout, proxies=self.proxies
168168
)
169169

170-
og_pid_regex = r'https:\/\/accounts\.google\.com\/ListAccounts\?authuser=[0-9]+\\u0026pid=([0-9]+)'
170+
og_pid_regex = r"https:\/\/accounts\.google\.com\/ListAccounts\?authuser=[0-9]+\\u0026pid=([0-9]+)"
171171
exp_id_regex = r'https:\/\/accounts\.google\.com\/RotateCookiesPage"],([0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+)'
172172

173-
174173
matches_og_pid = re.search(og_pid_regex, resp.text)
175174
matches_exp_id = re.search(exp_id_regex, resp.text)
176-
175+
177176
print(matches_og_pid, matches_exp_id)
178177
if matches_og_pid:
179178
og_pid_url = matches_og_pid.group(0)
180179
og_pid_query = urlparse(og_pid_url.replace("\\u0026", "&")).query
181180
print(og_pid_query)
182-
og_pid = parse_qs(og_pid_query)['pid'][0]
181+
og_pid = parse_qs(og_pid_query)["pid"][0]
183182
print(f"og_pid: {og_pid}")
184183
self.og_pid = og_pid
185184

186185
if matches_exp_id:
187186
values_str = matches_exp_id.group(1)
188-
values_array = [int(val) for val in values_str.split(',')]
187+
values_array = [int(val) for val in values_str.split(",")]
189188
print(f"Values array: {values_array}")
190189

191190
if len(values_array) >= 5:
@@ -202,43 +201,53 @@ def _set_cookie_refresh_data(self):
202201
# Update cookies using the extracted og_pid and exp_id
203202
update_cookies_url = f"https://accounts.google.com/RotateCookiesPage?og_pid={self.og_pid}&rot={self.rot}&origin=https%3A%2F%2Fbard.google.com&exp_id={self.exp_id}"
204203
headers_google = {
205-
'Host': 'accounts.google.com',
206-
'Referer': 'https://bard.google.com/',
207-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36',
204+
"Host": "accounts.google.com",
205+
"Referer": "https://bard.google.com/",
206+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
208207
}
209208

210209
try:
211-
response = self.session.get(update_cookies_url, headers=headers_google, timeout=self.timeout, proxies=self.proxies)
210+
response = self.session.get(
211+
update_cookies_url,
212+
headers=headers_google,
213+
timeout=self.timeout,
214+
proxies=self.proxies,
215+
)
212216
response.raise_for_status()
213217
except requests.exceptions.HTTPError as err:
214218
print(f"HTTP Error: {err}")
215219
# Extract initValue from the updated cookies
216220
print(response.text)
217-
init_value_regex = r'init\(\'(-?\d+)\','
221+
init_value_regex = r"init\(\'(-?\d+)\',"
218222
matches_init_value = re.findall(init_value_regex, response.text)
219223
print(matches_init_value)
220224
if matches_init_value:
221225
self.init_value = matches_init_value[0]
222226

223-
224227
def update_1PSIDTS(self):
225228
# Prepare request data
226229
self._set_cookie_refresh_data()
227-
data = [self.og_pid, f'{self.init_value}']
230+
data = [self.og_pid, f"{self.init_value}"]
228231
data = json.dumps(data)
229232
update_cookies_url = f"https://accounts.google.com/RotateCookiesPage?og_pid={self.og_pid}&rot={self.rot}&origin=https%3A%2F%2Fbard.google.com&exp_id={self.exp_id}"
230233

231234
# Update 1PSIDTS using the extracted og_pid and initValue
232235
update_1psidts_url = "https://accounts.google.com/RotateCookies"
233236
headers_rotate = {
234-
'Host': 'accounts.google.com',
237+
"Host": "accounts.google.com",
235238
"Content-Type": "application/json",
236-
'Referer': update_cookies_url,
237-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36',
239+
"Referer": update_cookies_url,
240+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
238241
}
239242
# headers_rotate.update(self.headers)
240243

241-
response = self.session.post(update_1psidts_url, data=data, headers=headers_rotate, timeout=self.timeout, proxies=self.proxies)
244+
response = self.session.post(
245+
update_1psidts_url,
246+
data=data,
247+
headers=headers_rotate,
248+
timeout=self.timeout,
249+
proxies=self.proxies,
250+
)
242251
response.raise_for_status()
243252

244253
# Extract updated 1PSIDTS from the response headers

test.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)