summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/you
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-21 15:15:55 +0200
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-21 15:15:55 +0200
commita26421bcd8b8580650fa05b3fb4f8fdfa0ef9921 (patch)
treeb1c7ff275c54682e29f89f07638b8fdd1743e0e1 /g4f/Provider/you
parentAdd MissingRequirementsError to You (diff)
downloadgpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.tar
gpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.tar.gz
gpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.tar.bz2
gpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.tar.lz
gpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.tar.xz
gpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.tar.zst
gpt4free-a26421bcd8b8580650fa05b3fb4f8fdfa0ef9921.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/you/har_file.py67
1 files changed, 17 insertions, 50 deletions
diff --git a/g4f/Provider/you/har_file.py b/g4f/Provider/you/har_file.py
index 18a7144b..e58e44d6 100644
--- a/g4f/Provider/you/har_file.py
+++ b/g4f/Provider/you/har_file.py
@@ -4,7 +4,6 @@ import json
import os
import os.path
import random
-import requests
from ...requests import StreamSession, raise_for_status
from ...errors import MissingRequirementsError
@@ -21,7 +20,8 @@ class arkReq:
self.arkCookies = arkCookies
self.userAgent = userAgent
-arkPreURL = "https://telemetry.stytch.com/submit"
+telemetry_url = "https://telemetry.stytch.com/submit"
+public_token = "public-token-live-507a52ad-7e69-496b-aee0-1c9863c7c819"
chatArks: list = None
def readHAR():
@@ -44,7 +44,7 @@ def readHAR():
# Error: not a HAR file!
continue
for v in harFile['log']['entries']:
- if arkPreURL in v['request']['url']:
+ if v['request']['url'] == telemetry_url:
chatArks.append(parseHAREntry(v))
if not chatArks:
raise NoValidHarFileError("No telemetry in .har files found")
@@ -62,24 +62,29 @@ def parseHAREntry(entry) -> arkReq:
return tmpArk
async def sendRequest(tmpArk: arkReq, proxy: str = None):
- async with StreamSession(headers=tmpArk.arkHeaders, cookies=tmpArk.arkCookies, proxies={"all": proxy}) as session:
+ async with StreamSession(headers=tmpArk.arkHeaders, cookies=tmpArk.arkCookies, proxy=proxy) as session:
async with session.post(tmpArk.arkURL, data=tmpArk.arkBody) as response:
await raise_for_status(response)
return await response.text()
-async def get_dfp_telemetry_id(proxy: str = None):
+async def create_telemetry_id(proxy: str = None):
global chatArks
if chatArks is None:
chatArks = readHAR()
return await sendRequest(random.choice(chatArks), proxy)
async def get_telemetry_ids(proxy: str = None) -> list:
+ try:
+ return [await create_telemetry_id(proxy)]
+ except NoValidHarFileError as e:
+ if debug.logging:
+ print(e)
if debug.logging:
print('Getting telemetry_id for you.com with nodriver')
try:
from nodriver import start
except ImportError:
- raise MissingRequirementsError('Install "nodriver" package | pip install -U nodriver')
+ raise MissingRequirementsError('Add .har file from you.com or install "nodriver" package | pip install -U nodriver')
try:
browser = await start()
tab = browser.main_tab
@@ -89,49 +94,11 @@ async def get_telemetry_ids(proxy: str = None) -> list:
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)
-
- # for _ in range(500):
- # with open("hardir/you.com_telemetry_ids.txt", "a") as f:
- # f.write((await get_telemetry_id()) + "\n")
+ return await tab.evaluate(
+ f'this.GetTelemetryID("{public_token}", "{telemetry_url}");',
+ await_promise=True
+ )
- return [await get_telemetry_id() for _ in range(4)]
+ return [await get_telemetry_id() for _ in range(1)]
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:
- pass
-
- headers = {
- 'Accept': '*/*',
- 'Accept-Language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
- 'Connection': 'keep-alive',
- 'Content-type': 'application/x-www-form-urlencoded',
- 'Origin': 'https://you.com',
- 'Referer': 'https://you.com/',
- 'Sec-Fetch-Dest': 'empty',
- 'Sec-Fetch-Mode': 'cors',
- 'Sec-Fetch-Site': 'cross-site',
- 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
- 'sec-ch-ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"',
- 'sec-ch-ua-mobile': '?0',
- 'sec-ch-ua-platform': '"macOS"',
- }
-
- proxies = {
- 'http': proxy,
- 'https': proxy} if proxy else None
-
- response = requests.post('https://telemetry.stytch.com/submit',
- headers=headers, data=payload, proxies=proxies)
-
- if '-' in response.text:
- print(f'telemetry generated: {response.text}')
-
- return (response.text)
+ await browser.stop() \ No newline at end of file