diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-04-21 07:45:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-21 07:45:23 +0200 |
commit | 0f3935f1c068c723342153dd040e0e72e95aa11b (patch) | |
tree | c4d1e9c9eb2ebfe13e2679afe8a23d7ffa45fa46 /g4f/Provider/you/har_file.py | |
parent | Merge pull request #1865 from hlohaus/carst (diff) | |
parent | Add MissingRequirementsError to You (diff) | |
download | gpt4free-0f3935f1c068c723342153dd040e0e72e95aa11b.tar gpt4free-0f3935f1c068c723342153dd040e0e72e95aa11b.tar.gz gpt4free-0f3935f1c068c723342153dd040e0e72e95aa11b.tar.bz2 gpt4free-0f3935f1c068c723342153dd040e0e72e95aa11b.tar.lz gpt4free-0f3935f1c068c723342153dd040e0e72e95aa11b.tar.xz gpt4free-0f3935f1c068c723342153dd040e0e72e95aa11b.tar.zst gpt4free-0f3935f1c068c723342153dd040e0e72e95aa11b.zip |
Diffstat (limited to 'g4f/Provider/you/har_file.py')
-rw-r--r-- | g4f/Provider/you/har_file.py | 52 |
1 files changed, 17 insertions, 35 deletions
diff --git a/g4f/Provider/you/har_file.py b/g4f/Provider/you/har_file.py index a6981296..18a7144b 100644 --- a/g4f/Provider/you/har_file.py +++ b/g4f/Provider/you/har_file.py @@ -2,12 +2,13 @@ from __future__ import annotations import json import os +import os.path import random -import uuid -import asyncio import requests from ...requests import StreamSession, raise_for_status +from ...errors import MissingRequirementsError +from ... import debug class NoValidHarFileError(Exception): ... @@ -67,60 +68,41 @@ 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') +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 - + raise MissingRequirementsError('Install "nodriver" package | pip install -U nodriver') 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(4)] 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: |