From 5913cca366c7546255dd3fe8d4f633825dc5aa7b Mon Sep 17 00:00:00 2001 From: "[object Object]" Date: Wed, 13 Nov 2024 10:31:10 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8E=20=D1=8E?= =?UTF-8?q?=D0=B7=D0=B5=D1=80=20=D0=B0=D0=B3=D0=B5=D0=BD=D1=82=D0=B0,=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hh_applicant_tool/api/client.py | 19 ++++++++++++++++++- hh_applicant_tool/constants.py | 2 +- hh_applicant_tool/operations/apply_similar.py | 4 ++-- hh_applicant_tool/telemetry_client.py | 2 -- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/hh_applicant_tool/api/client.py b/hh_applicant_tool/api/client.py index 0b33cfb..ba752f8 100644 --- a/hh_applicant_tool/api/client.py +++ b/hh_applicant_tool/api/client.py @@ -54,7 +54,24 @@ def __post_init__(self) -> None: logger.debug("Default Headers: %r", session.headers) def default_user_agent(self) -> str: - return USER_AGENT_TEMPLATE % random.randint(88, 130) + return USER_AGENT_TEMPLATE % ( + random.choice(["8.0", "8.1", "9", "10", "11", "12"]), + random.choice( + [ + "SM-G998B", # Samsung Galaxy S21 Ultra + "Pixel 6", # Google Pixel 6 + "Mi 11", # Xiaomi Mi 11 + "OnePlus 9", # OnePlus 9 + "P40", # Huawei P40 + "LG G8", # LG G8 + "Xperia 1 II", # Sony Xperia 1 II + "Moto G Power", # Motorola Moto G Power + "HTC U12+", # HTC U12+ + "ROG Phone 5", # Asus ROG Phone 5 + ] + ), + random.randint(88, 130), + ) def additional_headers( self, diff --git a/hh_applicant_tool/constants.py b/hh_applicant_tool/constants.py index 85f4e77..38c4c03 100644 --- a/hh_applicant_tool/constants.py +++ b/hh_applicant_tool/constants.py @@ -1,4 +1,4 @@ -USER_AGENT_TEMPLATE = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%d.0.0.0 Mobile Safari/537.36" +USER_AGENT_TEMPLATE = "Mozilla/5.0 (Linux; Android %s; %s) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s.0.0.0 Mobile Safari/537.36" ANDROID_CLIENT_ID = ( "HIOMIAS39CA9DICTA7JIO64LQKQJF5AGIK74G9ITJKLNEDAOH5FHS5G1JI7FOEGD" diff --git a/hh_applicant_tool/operations/apply_similar.py b/hh_applicant_tool/operations/apply_similar.py index 8fe9c1f..2e3e70c 100644 --- a/hh_applicant_tool/operations/apply_similar.py +++ b/hh_applicant_tool/operations/apply_similar.py @@ -174,7 +174,7 @@ def _apply_similar( try: employer_id = vacancy["employer"]["id"] - except IndexError: + except KeyError: logger.warning( f"Вакансия без работодателя: {vacancy['alternate_url']}" ) @@ -205,7 +205,7 @@ def _apply_similar( message_template = random.choice(application_messages) try: - params["message"] = template_message % vacancy + params["message"] = message_template % vacancy except TypeError as ex: # TypeError: not enough arguments for format string # API HH все кривое, иногда нет идентификатора работодателя, иногда у вакансии нет названия. diff --git a/hh_applicant_tool/telemetry_client.py b/hh_applicant_tool/telemetry_client.py index 2a70dbc..a1f5ee8 100644 --- a/hh_applicant_tool/telemetry_client.py +++ b/hh_applicant_tool/telemetry_client.py @@ -51,8 +51,6 @@ def send_telemetry( :raises TelemetryError: Если произошла ошибка при отправке или декодировании JSON. """ url = urljoin(self.server_address, endpoint) - logger.debug(data) - try: response = self.session.post(url, json=data) # response.raise_for_status()