Untitled

mail@pastecode.io avatar
unknown
python
a year ago
896 B
1
Indexable
Never
def predict_rub_salary(vacancy):
    url = 'https://api.hh.ru/vacancies'
    payload = {'User-Agent': 'Elizabethsweden@yandex.ru',
    "professional_role": "96",
    "area":"1",
    "period":"30",
    "text": "Python",
    "only_with_salary": True
    }
    response = requests.get(url, params=payload)
    response.raise_for_status()
    vacancy_response = response.json()
    for vacancy in vacancy_response["items"]:
        vacancy_salary = vacancy["salary"]
        salary_from = vacancy_salary["from"]
        salary_to = vacancy_salary["to"]
        salary_currency = vacancy_salary["currency"]
    if salary_currency != "RUR" and salary_currency != "rub":
        return None
    if salary_from and salary_to:
        return (salary_from + salary_to) / 2
    elif salary_to:
        return salary_to * 0.8
    elif salary_from:
        return salary_from * 1.2
predict_rub_salary(vacancy)