Skip to content

Commit

Permalink
изменил генерацию юзер агента, исправил ошибки
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rgeym committed Nov 13, 2024
1 parent 3cf5e3d commit 5913cca
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
19 changes: 18 additions & 1 deletion hh_applicant_tool/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion hh_applicant_tool/constants.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions hh_applicant_tool/operations/apply_similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _apply_similar(

try:
employer_id = vacancy["employer"]["id"]
except IndexError:
except KeyError:
logger.warning(
f"Вакансия без работодателя: {vacancy['alternate_url']}"
)
Expand Down Expand Up @@ -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 все кривое, иногда нет идентификатора работодателя, иногда у вакансии нет названия.
Expand Down
2 changes: 0 additions & 2 deletions hh_applicant_tool/telemetry_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5913cca

Please sign in to comment.