Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import re
- csv_file = input()
- def print_vacancies(vacancies_dictionary: list, russ_wildcard: dict):
- for key in vacancies_dictionary.keys():
- print(f'{russ_wildcard[key]}: {vacancies_dictionary[key]}')
- print()
- def csv_filer(headlines: list, vacancies_list: list):
- russ_wildcard = {
- headlines[0]: 'Название', headlines[1]: 'Описание',
- headlines[2]: 'Навыки', headlines[3]: 'Опыт работы',
- headlines[4]: 'Премиум-вакансия', headlines[5]: 'Компания',
- headlines[6]: 'Нижняя граница вилки оклада', headlines[7]: 'Верхняя граница вилки оклада',
- headlines[8]: 'Оклад указан до вычета налогов', headlines[9]: 'Идентификатор валюты оклада',
- headlines[10]: 'Название региона', headlines[11]: 'Дата и время публикации вакансии'
- }
- index_key_skills = headlines.index('key_skills')
- index_salary_gross = headlines.index('salary_gross')
- index_salary_currency = headlines.index('salary_currency')
- index_premium = headlines.index('premium')
- html_tags = re.compile(r'<[^>]+>')
- for line in vacancies_list:
- if len(line) < len(headlines) or \
- line[index_salary_currency] != 'RUR':
- continue
- is_correct_string = True
- for index, value in enumerate(line):
- current_value = value
- if index != index_key_skills:
- current_value = re.sub(html_tags, '', current_value).strip()
- current_value = ' '.join(current_value.split())
- if index == index_salary_gross or \
- index == index_premium:
- if current_value == 'False':
- current_value = 'Нет'
- elif current_value == 'True':
- current_value = 'Да'
- else:
- current_value = current_value.strip()
- current_value = re.split("\n|\n\r", current_value)
- line[index] = current_value
- if len(value) == 0:
- is_correct_string = False
- break
- if is_correct_string:
- dictionary = {headlines[i]: line[i] for i in range(len(headlines))}
- print_vacancies(vacancies_dictionary=dictionary,
- russ_wildcard=russ_wildcard)
- def csv_reader(csv_name: str):
- with open(csv_name, 'r', encoding='utf-8') as file:
- reader = csv.reader(file)
- csv_filer(headlines=next(reader),
- vacancies_list=list(reader))
- csv_reader(csv_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement