make 9/10 func
This commit is contained in:
parent
72d5a28f16
commit
7555dc3319
@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import csv
|
||||||
|
from collections import Counter
|
||||||
def load_vacancies(filepath: str) -> list[dict]:
|
def load_vacancies(filepath: str) -> list[dict]:
|
||||||
try:
|
try:
|
||||||
with open(filepath,"r") as file:
|
with open(filepath,"r") as file:
|
||||||
@ -10,21 +11,61 @@ def load_vacancies(filepath: str) -> list[dict]:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
def filter_by_city(vacancies: list[dict], city: str) -> list[dict]:
|
def filter_by_city(vacancies: list[dict], city: str) -> list[dict]:
|
||||||
return [i for i in vacancies if i.get('city').lower() == city.lower()]
|
return [i for i in vacancies if i.get('city','').lower() == city.lower()]
|
||||||
def filter_by_skills(vacancies: list[dict], required_skills: list[str]) -> list[dict]:
|
def filter_by_skills(vacancies: list[dict], required_skills: list[str]) -> list[dict]:
|
||||||
return [i for i in vacancies if i.get('skills')]
|
return [i for i in vacancies if all(skill.lower() in set(k.lower() for k in i.get('skills')) for skill in required_skills ) ]
|
||||||
def filter_by_salary(vacancies: list[dict], min_salary: int) -> list[dict]:
|
def filter_by_salary(vacancies: list[dict], min_salary: int) -> list[dict]:
|
||||||
return []
|
return [v for v in vacancies if v.get('salary_to') and v.get('salary_from') and v.get('salary_to')>= min_salary and v.get('salary_form')> min_salary]
|
||||||
def extract_unique_companies(vacancies: list[dict]) -> list[str]:
|
def extract_unique_companies(vacancies: list[dict]) -> list[str]:
|
||||||
return []
|
return {v.get('company') for v in vacancies if v.get('company')}
|
||||||
def extract_top_skills(vacancies: list[dict], top_n: int) -> list[tuple[str, int]]:
|
def extract_top_skills(vacancies: list[dict], top_n: int) -> list[tuple[str, int]]:
|
||||||
return []
|
all_skills = []
|
||||||
|
for v in vacancies:
|
||||||
|
all_skills.extend(v.get('skills', []))
|
||||||
|
|
||||||
|
skill_counts = Counter(all_skills)
|
||||||
|
return skill_counts.most_common(top_n)
|
||||||
def calculate_average_salary(vacancies: list[dict]) -> float:
|
def calculate_average_salary(vacancies: list[dict]) -> float:
|
||||||
|
if not vacancies:
|
||||||
return 0.0
|
return 0.0
|
||||||
|
else:
|
||||||
|
salaries = []
|
||||||
|
for v in vacancies:
|
||||||
|
salary_from = v.get('salary_from')
|
||||||
|
salary_to = v.get('salary_to')
|
||||||
|
|
||||||
|
if salary_from is not None and salary_to is not None:
|
||||||
|
salaries.append((salary_from + salary_to) / 2)
|
||||||
|
elif salary_from is not None:
|
||||||
|
salaries.append(salary_from)
|
||||||
|
elif salary_to is not None:
|
||||||
|
salaries.append(salary_to)
|
||||||
|
|
||||||
|
if not salaries:
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
return sum(salaries) / len(salaries)
|
||||||
def group_by_company(vacancies: list[dict]) -> dict[str, int]:
|
def group_by_company(vacancies: list[dict]) -> dict[str, int]:
|
||||||
return {}
|
all_company = []
|
||||||
|
for v in vacancies:
|
||||||
|
all_company.append(v.get('company'))
|
||||||
|
company_count = Counter(all_company)
|
||||||
|
return company_count
|
||||||
def format_vacancy_short(vacancy: dict) -> str:
|
def format_vacancy_short(vacancy: dict) -> str:
|
||||||
return
|
salary_from = vacancy.get('salary_from')
|
||||||
|
salary_to = vacancy.get('salary_to')
|
||||||
|
|
||||||
|
if salary_from is not None and salary_to is not None:
|
||||||
|
salary_str = f"от {salary_from} до {salary_to}"
|
||||||
|
elif salary_from is not None:
|
||||||
|
salary_str = f"от {salary_from}"
|
||||||
|
elif salary_to is not None:
|
||||||
|
salary_str = f"до {salary_to}"
|
||||||
|
else:
|
||||||
|
salary_str = "зарплата не указана"
|
||||||
|
|
||||||
|
return (f"ID {vacancy.get('id')}: {vacancy.get('title')} в {vacancy.get('company')}, "
|
||||||
|
f"{vacancy.get('city')} — {salary_str}")
|
||||||
def save_filtered_results(vacancies: list[dict], filename: str) -> bool:
|
def save_filtered_results(vacancies: list[dict], filename: str) -> bool:
|
||||||
return
|
return
|
||||||
def interface():
|
def interface():
|
||||||
@ -32,15 +73,18 @@ def interface():
|
|||||||
print ("Your command:")
|
print ("Your command:")
|
||||||
print ("1. Load form json\n2. Filter by city\n3. Filter by skils\n4. Filter by salary")
|
print ("1. Load form json\n2. Filter by city\n3. Filter by skils\n4. Filter by salary")
|
||||||
print ("5. Extract unique companies\n6. Extract top skills\n7. Calculate average salary")
|
print ("5. Extract unique companies\n6. Extract top skills\n7. Calculate average salary")
|
||||||
print ("8. Group by company\n9. Format vacancy short\n10. Save filtred results")
|
print ("8. Group by company\n9. Format vacancy short\n10. Save filtred results\n11. Exit")
|
||||||
def user_chouse(user_input:int):
|
def user_chouse(user_input:int):
|
||||||
match user_input:
|
match user_input:
|
||||||
case 1:
|
case 1:
|
||||||
|
|
||||||
return load_vacancies(input("Path for json: "))
|
return load_vacancies(input("Path for json: "))
|
||||||
|
case 11:
|
||||||
|
return
|
||||||
case _:
|
case _:
|
||||||
print ("Error uncorrecteble number")
|
print ("Error uncorrecteble number")
|
||||||
def main():
|
def main():
|
||||||
|
while (user_input != 11):
|
||||||
interface()
|
interface()
|
||||||
user_input = int(input("Chouse command: "))
|
user_input = int(input("Chouse command: "))
|
||||||
user_chouse(user_input)
|
user_chouse(user_input)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user