Untitled

mail@pastecode.io avatar
unknown
python
a year ago
1.6 kB
2
Indexable
Never
import requests


def find_rub_salary(salary_from, salary_to, 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


def get_salary_statistic():
    salaries = []
    #language=["Python","Java","Go","Javascript","C#","C","PHP","Ruby"]
    url = 'https://api.hh.ru/vacancies'
    payload = {'User-Agent': 'Elizabethsweden@yandex.ru',
    "professional_role": "96",
    "area":"1",
    "period":"30",
    #"text": f"Программист{language}",
    "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"]
        salary = find_rub_salary(salary_from, salary_to, salary_currency)
        if salary:
            salaries.append(salary)
    vacancies_found = vacancy_response["found"]
    vacancies_processed = len(salaries)
    if vacancies_processed:
        average_salary = sum(salaries) // vacancies_processed
    return { 
        "vacancies_found": vacancies_found,
        "vacancies_processed": vacancies_processed,
        "average_salary": average_salary
    }

get_salary_statistic()