From f66cd9f8a322edd9cda4551b2a041559c4c82b2a Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 21 Apr 2024 07:38:36 +0200 Subject: Add MissingRequirementsError to You --- g4f/Provider/you/har_file.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'g4f/Provider/you') diff --git a/g4f/Provider/you/har_file.py b/g4f/Provider/you/har_file.py index 9d841352..18a7144b 100644 --- a/g4f/Provider/you/har_file.py +++ b/g4f/Provider/you/har_file.py @@ -2,10 +2,12 @@ from __future__ import annotations import json import os +import os.path import random import requests from ...requests import StreamSession, raise_for_status +from ...errors import MissingRequirementsError from ... import debug class NoValidHarFileError(Exception): @@ -71,21 +73,13 @@ async def get_dfp_telemetry_id(proxy: str = None): chatArks = readHAR() return await sendRequest(random.choice(chatArks), proxy) -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: from nodriver import start except ImportError: - if debug.logging: - print('Install "nodriver" package | pip install -U nodriver') - return read_telemetry_file() + raise MissingRequirementsError('Install "nodriver" package | pip install -U nodriver') try: browser = await start() tab = browser.main_tab @@ -103,7 +97,7 @@ async def get_telemetry_ids(proxy: str = None) -> list: # 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)] + return [await get_telemetry_id() for _ in range(4)] finally: try: await tab.close() -- cgit v1.2.3