Merge branch 'only_task'
This commit is contained in:
commit
e9754677c9
1
answer/1try.txt
Normal file
1
answer/1try.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
ID 2: Data Engineer в Тинькофф, Москва — от 180000 до 250000ID 6: Senior Python Developer в Wildberries, Москва — от 200000 до 300000
|
||||||
@ -1,9 +1,9 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"title": "Python ðàçðàáîò÷èê",
|
"title": "Python разработчик",
|
||||||
"company": "ßíäåêñ",
|
"company": "Яндекс",
|
||||||
"city": "Ìîñêâà",
|
"city": "Москва",
|
||||||
"salary_from": 150000,
|
"salary_from": 150000,
|
||||||
"salary_to": 200000,
|
"salary_to": 200000,
|
||||||
"skills": ["Python", "SQL", "Django", "PostgreSQL"],
|
"skills": ["Python", "SQL", "Django", "PostgreSQL"],
|
||||||
@ -12,8 +12,8 @@
|
|||||||
{
|
{
|
||||||
"id": 2,
|
"id": 2,
|
||||||
"title": "Data Engineer",
|
"title": "Data Engineer",
|
||||||
"company": "Òèíüêîôô",
|
"company": "Тинькофф",
|
||||||
"city": "Ìîñêâà",
|
"city": "Москва",
|
||||||
"salary_from": 180000,
|
"salary_from": 180000,
|
||||||
"salary_to": 250000,
|
"salary_to": 250000,
|
||||||
"skills": ["Python", "SQL", "Spark", "Airflow"],
|
"skills": ["Python", "SQL", "Spark", "Airflow"],
|
||||||
@ -23,7 +23,7 @@
|
|||||||
"id": 3,
|
"id": 3,
|
||||||
"title": "Backend Developer",
|
"title": "Backend Developer",
|
||||||
"company": "Ozon",
|
"company": "Ozon",
|
||||||
"city": "Ñàíêò-Ïåòåðáóðã",
|
"city": "Санкт-Петербург",
|
||||||
"salary_from": 130000,
|
"salary_from": 130000,
|
||||||
"salary_to": 170000,
|
"salary_to": 170000,
|
||||||
"skills": ["Python", "FastAPI", "MongoDB"],
|
"skills": ["Python", "FastAPI", "MongoDB"],
|
||||||
@ -32,8 +32,8 @@
|
|||||||
{
|
{
|
||||||
"id": 4,
|
"id": 4,
|
||||||
"title": "Data Analyst",
|
"title": "Data Analyst",
|
||||||
"company": "ßíäåêñ",
|
"company": "Яндекс",
|
||||||
"city": "Ìîñêâà",
|
"city": "Москва",
|
||||||
"salary_from": 140000,
|
"salary_from": 140000,
|
||||||
"salary_to": 180000,
|
"salary_to": 180000,
|
||||||
"skills": ["Python", "SQL", "Tableau"],
|
"skills": ["Python", "SQL", "Tableau"],
|
||||||
@ -42,8 +42,8 @@
|
|||||||
{
|
{
|
||||||
"id": 5,
|
"id": 5,
|
||||||
"title": "Junior Python Developer",
|
"title": "Junior Python Developer",
|
||||||
"company": "Ñáåð",
|
"company": "Сбер",
|
||||||
"city": "Ìîñêâà",
|
"city": "Москва",
|
||||||
"salary_from": 100000,
|
"salary_from": 100000,
|
||||||
"salary_to": 130000,
|
"salary_to": 130000,
|
||||||
"skills": ["Python", "SQL", "Git"],
|
"skills": ["Python", "SQL", "Git"],
|
||||||
@ -53,7 +53,7 @@
|
|||||||
"id": 6,
|
"id": 6,
|
||||||
"title": "Senior Python Developer",
|
"title": "Senior Python Developer",
|
||||||
"company": "Wildberries",
|
"company": "Wildberries",
|
||||||
"city": "Ìîñêâà",
|
"city": "Москва",
|
||||||
"salary_from": 200000,
|
"salary_from": 200000,
|
||||||
"salary_to": 300000,
|
"salary_to": 300000,
|
||||||
"skills": ["Python", "SQL", "Kafka", "Kubernetes"],
|
"skills": ["Python", "SQL", "Kafka", "Kubernetes"],
|
||||||
@ -63,7 +63,7 @@
|
|||||||
"id": 7,
|
"id": 7,
|
||||||
"title": "Full Stack Developer",
|
"title": "Full Stack Developer",
|
||||||
"company": "Avito",
|
"company": "Avito",
|
||||||
"city": "Ìîñêâà",
|
"city": "Москва",
|
||||||
"salary_from": 170000,
|
"salary_from": 170000,
|
||||||
"salary_to": 220000,
|
"salary_to": 220000,
|
||||||
"skills": ["Python", "JavaScript", "React", "SQL"],
|
"skills": ["Python", "JavaScript", "React", "SQL"],
|
||||||
|
|||||||
@ -1,28 +1,24 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import csv
|
|
||||||
from collections import Counter
|
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:
|
||||||
return json.load(file)
|
return json.load(file)
|
||||||
except:
|
except:
|
||||||
print()
|
print()
|
||||||
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 all(skill.lower() in set(k.lower() for k in i.get('skills')) for skill in required_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 [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]
|
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_from')> min_salary]
|
||||||
def extract_unique_companies(vacancies: list[dict]) -> list[str]:
|
def extract_unique_companies(vacancies: list[dict]) -> list[str]:
|
||||||
return {v.get('company') for v in vacancies if v.get('company')}
|
return list({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]]:
|
||||||
all_skills = []
|
all_skills = []
|
||||||
for v in vacancies:
|
for v in vacancies:
|
||||||
all_skills.extend(v.get('skills', []))
|
all_skills.extend(v.get('skills', []))
|
||||||
|
|
||||||
skill_counts = Counter(all_skills)
|
skill_counts = Counter(all_skills)
|
||||||
return skill_counts.most_common(top_n)
|
return skill_counts.most_common(top_n)
|
||||||
def calculate_average_salary(vacancies: list[dict]) -> float:
|
def calculate_average_salary(vacancies: list[dict]) -> float:
|
||||||
@ -33,17 +29,14 @@ def calculate_average_salary(vacancies: list[dict]) -> float:
|
|||||||
for v in vacancies:
|
for v in vacancies:
|
||||||
salary_from = v.get('salary_from')
|
salary_from = v.get('salary_from')
|
||||||
salary_to = v.get('salary_to')
|
salary_to = v.get('salary_to')
|
||||||
|
|
||||||
if salary_from is not None and salary_to is not None:
|
if salary_from is not None and salary_to is not None:
|
||||||
salaries.append((salary_from + salary_to) / 2)
|
salaries.append((salary_from + salary_to) / 2)
|
||||||
elif salary_from is not None:
|
elif salary_from is not None:
|
||||||
salaries.append(salary_from)
|
salaries.append(salary_from)
|
||||||
elif salary_to is not None:
|
elif salary_to is not None:
|
||||||
salaries.append(salary_to)
|
salaries.append(salary_to)
|
||||||
|
|
||||||
if not salaries:
|
if not salaries:
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
return sum(salaries) / len(salaries)
|
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]:
|
||||||
all_company = []
|
all_company = []
|
||||||
@ -54,7 +47,6 @@ def group_by_company(vacancies: list[dict]) -> dict[str, int]:
|
|||||||
def format_vacancy_short(vacancy: dict) -> str:
|
def format_vacancy_short(vacancy: dict) -> str:
|
||||||
salary_from = vacancy.get('salary_from')
|
salary_from = vacancy.get('salary_from')
|
||||||
salary_to = vacancy.get('salary_to')
|
salary_to = vacancy.get('salary_to')
|
||||||
|
|
||||||
if salary_from is not None and salary_to is not None:
|
if salary_from is not None and salary_to is not None:
|
||||||
salary_str = f"от {salary_from} до {salary_to}"
|
salary_str = f"от {salary_from} до {salary_to}"
|
||||||
elif salary_from is not None:
|
elif salary_from is not None:
|
||||||
@ -63,32 +55,35 @@ def format_vacancy_short(vacancy: dict) -> str:
|
|||||||
salary_str = f"до {salary_to}"
|
salary_str = f"до {salary_to}"
|
||||||
else:
|
else:
|
||||||
salary_str = "зарплата не указана"
|
salary_str = "зарплата не указана"
|
||||||
|
|
||||||
return (f"ID {vacancy.get('id')}: {vacancy.get('title')} в {vacancy.get('company')}, "
|
return (f"ID {vacancy.get('id')}: {vacancy.get('title')} в {vacancy.get('company')}, "
|
||||||
f"{vacancy.get('city')} — {salary_str}")
|
f"{vacancy.get('city')} — {salary_str}\n")
|
||||||
def save_filtered_results(vacancies: list[dict], filename: str) -> bool:
|
def save_filtered_results(vacancies: list[dict], filename: str) -> bool:
|
||||||
return
|
try:
|
||||||
def interface():
|
with open(filename,"w") as file:
|
||||||
os.system('cls' if os.name == 'nt' else 'clear')
|
file.writelines(format_vacancy_short(x) for x in vacancies)
|
||||||
print ("Your command:")
|
return 0
|
||||||
print ("1. Load form json\n2. Filter by city\n3. Filter by skils\n4. Filter by salary")
|
except:
|
||||||
print ("5. Extract unique companies\n6. Extract top skills\n7. Calculate average salary")
|
return 1
|
||||||
print ("8. Group by company\n9. Format vacancy short\n10. Save filtred results\n11. Exit")
|
|
||||||
def user_chouse(user_input:int):
|
|
||||||
match user_input:
|
|
||||||
case 1:
|
|
||||||
|
|
||||||
return load_vacancies(input("Path for json: "))
|
|
||||||
case 11:
|
|
||||||
return
|
|
||||||
case _:
|
|
||||||
print ("Error uncorrecteble number")
|
|
||||||
def main():
|
def main():
|
||||||
while (user_input != 11):
|
main_list=load_vacancies(input("Write path for json:"))
|
||||||
interface()
|
filered_vacancies = filter_by_city(main_list,input("Write city"))
|
||||||
user_input = int(input("Chouse command: "))
|
skils_list=[]
|
||||||
user_chouse(user_input)
|
for i in range(int(input("Write number of skills: "))):
|
||||||
|
skils_list.append(input(f"Write №{i + 1} skill: "))
|
||||||
|
filered_vacancies=filter_by_skills(filered_vacancies,skils_list)
|
||||||
|
filered_vacancies = filter_by_salary(filered_vacancies,int(input("Write salary: ")))
|
||||||
|
print("Уникальные компании: ", ", ".join(extract_unique_companies(filered_vacancies)))
|
||||||
|
top_skills = extract_top_skills(filered_vacancies, 5)
|
||||||
|
print(f"Топ-5 навыков:")
|
||||||
|
for skill, count in top_skills:
|
||||||
|
print(f" {skill}: {count} вакансий")
|
||||||
|
print(f"\nСредняя зарплата: {calculate_average_salary(filered_vacancies):,.0f} руб.")
|
||||||
|
for company, count in group_by_company(filered_vacancies).items():
|
||||||
|
print(f" {company}: {count} вакансий")
|
||||||
|
if(save_filtered_results(filered_vacancies,input("Write where to save"))):
|
||||||
|
print("Check your path")
|
||||||
|
else:
|
||||||
|
print("Everything is fine, the file is saved")
|
||||||
if __name__ =="__main__":
|
if __name__ =="__main__":
|
||||||
#вход проги
|
#вход проги
|
||||||
main()
|
main()
|
||||||
Loading…
Reference in New Issue
Block a user