-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_vacancies_dict_for_sj.py
31 lines (28 loc) · 1.09 KB
/
get_vacancies_dict_for_sj.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import requests
from contextlib import suppress
import predict_rub_salary
def get_vacancies_sj(languages, api_id, count=1000):
vacancies = {}
for language in languages:
headers = {"X-Api-App-Id": api_id}
params = {"keyword": language, "count": count, "town": "Москва"}
response = requests.get(
"https://api.superjob.ru/2.0/vacancies/", headers=headers, params=params
)
response.raise_for_status()
contents = response.json()
salary_prediction = [
predict_rub_salary.predict_salary(
content["payment_from"], content["payment_to"]
)
for content in contents["objects"]
]
rub_salaries = [salary for salary in salary_prediction if salary]
with suppress(ZeroDivisionError):
average_salary = int(sum(rub_salaries) / len(rub_salaries))
vacancies[language] = {
"vacancies_found": contents["total"],
"vacancies_processed": len(rub_salaries),
"average_salary": average_salary,
}
return vacancies