Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import math
- import re
- from prettytable import PrettyTable
- def formatter(row: dict):
- dict_format = {
- "experience_id": {
- "noExperience": "Нет опыта",
- "between1And3": "От 1 года до 3 лет",
- "between3And6": "От 3 до 6 лет",
- "moreThan6": "Более 6 лет"},
- "premium": {
- 'True': 'Да',
- 'False': 'Нет'},
- "salary_gross": {
- 'False': 'С вычетом налогов',
- 'True': 'Без вычета налогов'},
- "salary_currency": {
- "AZN": "Манаты",
- "BYR": "Белорусские рубли",
- "EUR": "Евро",
- "GEL": "Грузинский лари",
- "KGS": "Киргизский сом",
- "KZT": "Тенге",
- "RUR": "Рубли",
- "UAH": "Гривны",
- "USD": "Доллары",
- "UZS": "Узбекский сум"}
- }
- row['salary_all'] = ''
- for key, value in row.items():
- if key == 'key_skills':
- row[key] = ", ".join(value)
- if key == 'experience_id':
- row[key] = dict_format[key][value]
- if key == 'premium':
- row[key] = dict_format[key][value]
- if key == 'salary_from':
- row[key] = '{:,}'.format(math.floor(float(row["salary_from"]))).replace(',', ' ')
- if key == 'salary_to':
- row[key] = '{:,}'.format(math.floor(float(row["salary_to"]))).replace(',', ' ')
- if key == 'salary_gross':
- row[key] = dict_format[key][value]
- if key == 'salary_currency':
- row['salary_all'] = f'{row["salary_from"]} - {row["salary_to"]} ' \
- f'({dict_format[key][value]}) ({row["salary_gross"]})'
- if key == 'published_at':
- row[key] = '.'.join(reversed(value[0:10].split('-')))
- return row
- def csv_reader(csv_name: str):
- with open(csv_name, encoding='utf-8-sig') as file:
- file_reader = csv.reader(file, delimiter=',')
- headlines = next(file_reader)
- raw_list = list(file_reader)
- # return [raw_list, headlines]
- csv_filer(raw_list=raw_list,
- headlines=headlines)
- def csv_filer(raw_list: list, headlines: list):
- vacancies_list = list()
- index_key_skills = headlines.index('key_skills')
- html_tags = re.compile('<.*?>')
- for line in raw_list:
- try:
- line.remove('')
- except ValueError:
- pass
- for index in range(len(line)):
- if index != index_key_skills:
- line[index] = ' '.join(re.sub(html_tags, '', line[index])
- .strip().split())
- else:
- line[index] = list(map(lambda x: x.strip(), line[index].split('\n')))
- if len(line) == len(headlines):
- vacancies_list.append({headlines[i]: line[i] for i in range(len(headlines))})
- # return vacancies_list
- print_vacancies(vacancies_list=vacancies_list)
- def print_vacancies(vacancies_list: list):
- for vacancy in vacancies_list:
- current_vacancy = formatter(vacancy)
- print(f'Название: {current_vacancy["name"]}\n'
- f'Описание: {current_vacancy["description"]}\n'
- f'Навыки: {current_vacancy["key_skills"]}\n'
- f'Опыт работы: {current_vacancy["experience_id"]}\n'
- f'Премиум-вакансия: {current_vacancy["premium"]}\n'
- f'Компания: {current_vacancy["employer_name"]}\n'
- f'Оклад: {current_vacancy["salary_all"]}\n'
- f'Название региона: {current_vacancy["area_name"]}\n'
- f'Дата публикации вакансии: {current_vacancy["published_at"]}\n')
- csv_file = 'vacancies_medium.csv'
- csv_reader(csv_file)
- table = PrettyTable()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement