Advertisement
mikhailemv

Untitled

Oct 4th, 2022
1,140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.73 KB | None | 0 0
  1. import csv
  2. import re
  3.  
  4. csv_file = input()
  5.  
  6.  
  7. def print_vacancies(vacancies_dictionary: list, russ_wildcard: dict):
  8.     for key in vacancies_dictionary.keys():
  9.         print(f'{russ_wildcard[key]}: {vacancies_dictionary[key]}')
  10.     print()
  11.  
  12.  
  13. def csv_filer(headlines: list, vacancies_list: list):
  14.     russ_wildcard = {
  15.         headlines[0]: 'Название', headlines[1]: 'Описание',
  16.         headlines[2]: 'Навыки', headlines[3]: 'Опыт работы',
  17.         headlines[4]: 'Премиум-вакансия', headlines[5]: 'Компания',
  18.         headlines[6]: 'Нижняя граница вилки оклада', headlines[7]: 'Верхняя граница вилки оклада',
  19.         headlines[8]: 'Оклад указан до вычета налогов', headlines[9]: 'Идентификатор валюты оклада',
  20.         headlines[10]: 'Название региона', headlines[11]: 'Дата и время публикации вакансии'
  21.     }
  22.     index_key_skills = headlines.index('key_skills')
  23.     index_salary_gross = headlines.index('salary_gross')
  24.     index_salary_currency = headlines.index('salary_currency')
  25.     index_premium = headlines.index('premium')
  26.     html_tags = re.compile(r'<[^>]+>')
  27.     for line in vacancies_list:
  28.         if len(line) < len(headlines) or \
  29.                 line[index_salary_currency] != 'RUR':
  30.             continue
  31.         is_correct_string = True
  32.         for index, value in enumerate(line):
  33.             current_value = value
  34.             if index != index_key_skills:
  35.                 current_value = re.sub(html_tags, '', current_value).strip()
  36.                 current_value = ' '.join(current_value.split())
  37.                 if index == index_salary_gross or \
  38.                         index == index_premium:
  39.                     if current_value == 'False':
  40.                         current_value = 'Нет'
  41.                     elif current_value == 'True':
  42.                         current_value = 'Да'
  43.             else:
  44.                 current_value = current_value.strip()
  45.                 current_value = re.split("\n|\n\r", current_value)
  46.             line[index] = current_value
  47.             if len(value) == 0:
  48.                 is_correct_string = False
  49.                 break
  50.         if is_correct_string:
  51.             dictionary = {headlines[i]: line[i] for i in range(len(headlines))}
  52.             print_vacancies(vacancies_dictionary=dictionary,
  53.                             russ_wildcard=russ_wildcard)
  54.  
  55.  
  56. def csv_reader(csv_name: str):
  57.     with open(csv_name, 'r', encoding='utf-8') as file:
  58.         reader = csv.reader(file)
  59.         csv_filer(headlines=next(reader),
  60.                   vacancies_list=list(reader))
  61.  
  62.  
  63. csv_reader(csv_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement