summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/you
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-21 07:22:59 +0200
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-21 07:22:59 +0200
commitdb2d6cffd9268e8842f0c2aa8e062c0e19d88d28 (patch)
tree2b44e3ec6e21a8c1270f3d84a4a1f0efb360d37b /g4f/Provider/you
parentDisable Bing integration test (diff)
downloadgpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.tar
gpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.tar.gz
gpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.tar.bz2
gpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.tar.lz
gpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.tar.xz
gpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.tar.zst
gpt4free-db2d6cffd9268e8842f0c2aa8e062c0e19d88d28.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/you/har_file.py58
1 files changed, 23 insertions, 35 deletions
diff --git a/g4f/Provider/you/har_file.py b/g4f/Provider/you/har_file.py
index a6981296..9d841352 100644
--- a/g4f/Provider/you/har_file.py
+++ b/g4f/Provider/you/har_file.py
@@ -3,11 +3,10 @@ from __future__ import annotations
import json
import os
import random
-import uuid
-import asyncio
import requests
from ...requests import StreamSession, raise_for_status
+from ... import debug
class NoValidHarFileError(Exception):
...
@@ -67,60 +66,49 @@ async def sendRequest(tmpArk: arkReq, proxy: str = None):
return await response.text()
async def get_dfp_telemetry_id(proxy: str = None):
- return await telemetry_id_with_driver(proxy)
global chatArks
if chatArks is None:
chatArks = readHAR()
return await sendRequest(random.choice(chatArks), proxy)
-async def telemetry_id_with_driver(proxy: str = None):
- from ...debug import logging
- if logging:
- print('getting telemetry_id for you.com with nodriver')
+def read_telemetry_file() -> list:
+ with open("hardir/you.com_telemetry_ids.txt", "r") as f:
+ ids = f.readlines()
+ random.shuffle(ids)
+ return ids
+
+async def get_telemetry_ids(proxy: str = None) -> list:
+ if debug.logging:
+ print('Getting telemetry_id for you.com with nodriver')
try:
- import nodriver as uc
- from nodriver import start, cdp, loop
+ from nodriver import start
except ImportError:
- if logging:
- print('nodriver not found, random uuid (may fail)')
- return str(uuid.uuid4())
-
- CAN_EVAL = False
- payload_received = False
- payload = None
-
+ if debug.logging:
+ print('Install "nodriver" package | pip install -U nodriver')
+ return read_telemetry_file()
try:
browser = await start()
tab = browser.main_tab
-
- async def send_handler(event: cdp.network.RequestWillBeSent):
- nonlocal CAN_EVAL, payload_received, payload
- if 'telemetry.js' in event.request.url:
- CAN_EVAL = True
- if "/submit" in event.request.url:
- payload = event.request.post_data
- payload_received = True
-
- tab.add_handler(cdp.network.RequestWillBeSent, send_handler)
await browser.get("https://you.com")
- while not CAN_EVAL:
+ while not await tab.evaluate('"GetTelemetryID" in this'):
await tab.sleep(1)
- await tab.evaluate('window.GetTelemetryID("public-token-live-507a52ad-7e69-496b-aee0-1c9863c7c819", "https://telemetry.stytch.com/submit");')
-
- while not payload_received:
- await tab.sleep(.1)
+ async def get_telemetry_id():
+ public_token = "public-token-live-507a52ad-7e69-496b-aee0-1c9863c7c819"
+ telemetry_url = "https://telemetry.stytch.com/submit"
+ return await tab.evaluate(f'this.GetTelemetryID("{public_token}", "{telemetry_url}");', await_promise=True)
- except Exception as e:
- print(f"Error occurred: {str(e)}")
+ # for _ in range(500):
+ # with open("hardir/you.com_telemetry_ids.txt", "a") as f:
+ # f.write((await get_telemetry_id()) + "\n")
+ return [await get_telemetry_id() for _ in range(10)]
finally:
try:
await tab.close()
except Exception as e:
print(f"Error occurred while closing tab: {str(e)}")
-
try:
await browser.stop()
except Exception as e: