Advertisement
mikhailemv

Untitled

Nov 28th, 2022
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.30 KB | None | 0 0
  1. import var_dump
  2. import csv
  3. import re
  4.  
  5.  
  6. class Salary:
  7.     def __init__(self,
  8.                  salary_from: str,
  9.                  salary_to: str,
  10.                  salary_gross: str,
  11.                  salary_currency: str) -> None:
  12.         self.salary_from = salary_from
  13.         self.salary_to = salary_to
  14.         self.salary_gross = salary_gross
  15.         self.salary_currency = salary_currency
  16.  
  17.  
  18. class DataSet:
  19.     def __init__(self,
  20.                  file_name: str,
  21.                  vacancies_objects: list) -> None:
  22.         self.file_name = file_name
  23.         self.vacancies_objects = vacancies_objects
  24.  
  25.     @staticmethod
  26.     def get_clean_string(raw_html) -> str:
  27.         return re.sub(re.compile('<.*?>'), '', raw_html)
  28.  
  29.     def csv_reader(self) -> tuple:
  30.         current_array, vacancies_for_job = list(), list()
  31.         with open(self.file_name, encoding='utf-8-sig') as r_file:
  32.             count = 0
  33.             cur_file = csv.reader(r_file, delimiter=",")
  34.             for row in cur_file:
  35.                 if count == 0:
  36.                     count += 1
  37.                     current_array = row
  38.                 else:
  39.                     if '' in row or len(row) != len(current_array):
  40.                         continue
  41.                     vacancies_for_job.append(row)
  42.         if len(current_array) == 0:
  43.             print('Пустой файл')
  44.             exit()
  45.         return vacancies_for_job, current_array
  46.  
  47.     def set_vacancies(self):
  48.         (vacancies, title) = self.csv_reader()
  49.         self.vacancies_objects = self.csv_filer(vacancies, title)
  50.  
  51.     def csv_filer(self, reader, my_list: list) -> list:
  52.         vacancies = list()
  53.         for row in reader:
  54.             current = dict()
  55.             for i in range(len(row)):
  56.                 current[my_list[i]] = row[i].split('\n')
  57.                 for j in range(len(current[my_list[i]])):
  58.                     current[my_list[i]][j] = ' '.join(self.get_clean_string(current[my_list[i]][j]).split())
  59.             vacancies.append(Vacancy(current))
  60.         return vacancies
  61.  
  62.  
  63. class Vacancy:
  64.     def __init__(self, object_vacancy) -> None:
  65.         self.name = object_vacancy['name'][0]
  66.         self.description = object_vacancy['description'][0]
  67.         self.key_skills = object_vacancy['key_skills']
  68.         self.experience_id = object_vacancy['experience_id'][0]
  69.         self.premium = object_vacancy['premium'][0]
  70.         self.employer_name = object_vacancy['employer_name'][0]
  71.         self.salary = Salary(object_vacancy['salary_from'][0], object_vacancy['salary_to'][0],
  72.                              object_vacancy['salary_gross'][0], object_vacancy['salary_currency'][0])
  73.         self.area_name = object_vacancy['area_name'][0]
  74.         self.published_at = object_vacancy['published_at'][0]
  75.  
  76.  
  77. file = input('Введите название файла: ')
  78. parameters = input('Введите параметр фильтрации: ')
  79. sort_parameters = input('Введите параметр сортировки: ')
  80. sort_descending = input('Обратный порядок сортировки (Да / Нет): ')
  81. output = input('Введите диапазон вывода: ')
  82. columns = input('Введите требуемые столбцы: ')
  83.  
  84. dataset = DataSet(file, list())
  85. dataset.set_vacancies()
  86. var_dump.var_dump(dataset)
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement