-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
129 lines (107 loc) · 5.1 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import csv
import pandas as pd
manager_file = 'empl_base_managers.csv'
worker_file = 'empl_base_workers.csv'
EMPL_LIST = []
# choose next option for for the notepad to do, according the user choice
def user_input():
note_action = input(f'Выберите нужное действие\nПоиск(П)/Сортировка(С)/Создание Списка(СП)\n')
note_action = note_action.upper()
if note_action == 'СОЗДАНИЕ СПИСКА' or note_action == 'СП':
list_cr()
if note_action == 'СОРТИРОВКА' or note_action == 'С':
srt_list = input('В каком списке произовдим сортировку?\nМенеджеры(М)/Работники Отделов(О)\n')
if srt_list.upper() == 'М' or srt_list.upper() == 'МЕНЕДЖЕРЫ':
sort_file(manager_file)
if srt_list.upper() == 'О' or srt_list.upper() == 'РАБОТНИКИ ОТДЕЛОВ':
sort_file(worker_file)
if note_action == 'ПОИСК' or note_action == 'П':
print('Данная функция ещё не введена')
user_input()
# search_emp = input('Введите Фамилия, Имя или Номер телефона\n')
# search_info(search_emp)
else:
user_input()
# add a list of employees to the list
def add_to_list(number_persons, file_name):
persons = number_persons
if len(persons.split(';')) > 1:
add_list = persons.split(';')
for i in add_list:
employee_info(i, file_name)
print(f'Все работники теперь полностью зарегестрированы')
else:
employee_info(persons, file_name)
read_file()
# divide one position in the list into name,surname,birth date,phone number and position
def employee_info(info, file_name):
one_person = info.split(',')
name = one_person[1].strip(' ')
surname = one_person[0].strip(' ')
birth_date = one_person[2].strip(' ')
phone_number = one_person[3].strip(' ')
if file_name == manager_file:
position = 'Менеджер'
else:
try:
position = one_person[4].strip(' ')
except IndexError:
position = input(f'Введите должность {name} {surname}: ')
EMPL_LIST.append({
'Фамилия': f'{name}',
'Имя': f'{surname}',
'Год рождения': f'{birth_date}',
'Номер телефона': f'{phone_number}',
'Должность': f'{position}'
})
save_file(EMPL_LIST, file_name)
# save the file in notepad's folder
def save_file(emp_list, file):
with open(file, 'w', encoding='UTF-8', newline='') as file:
writer = csv.writer(file)
writer.writerow(['Фамилия', 'Имя', 'Год рождения', 'Номер телефона', 'Должность'])
for position in emp_list:
writer.writerow([position['Имя'], position['Фамилия'], position['Год рождения'], position['Номер телефона'], position['Должность']])
# read the content of the file
def read_file():
try:
rfm = pd.read_csv(manager_file, encoding='utf-8')
print(rfm)
except FileNotFoundError:
print("Файл со списком менеджеров ещё не создан")
try:
rfe = pd.read_csv(worker_file, encoding='utf-8')
print(rfe)
except FileNotFoundError:
print("Файл со списком работников ещё не создан")
# sort the content of the file
def sort_file(file):
sort_opt = input('По каким критериями сортировать?\nФамилия/Год рождения:\n')
sf = pd.read_csv(file, encoding='utf-8')
sorted_list = sf.sort_values(sort_opt)
print(sorted_list)
# decide what list should be created
def list_cr():
ch_file = input('Выберите кого добавляем\nМендежер(М)/Работник отдела(О)\n')
ch_file = ch_file.upper()
try:
if ch_file == 'О' or ch_file == 'РАБОТНИК ОТДЕЛА':
emp_info = input('Введите данные работника: ')
add_to_list(ass_ch(emp_info), worker_file)
if ch_file == 'М' or ch_file == 'МЕНЕДЖЕР':
emp_info = input('Введите данные работника: ')
add_to_list(ass_ch(emp_info), manager_file)
except IndexError:
print('Данные введены не верным образом')
list_cr()
# delete an inappropriate symbol of separation
def ass_ch(info):
if info[-1] == ';':
info = info[0:-1]
return info
else:
return info
if __name__ == '__main__':
read_file()
user_input()
# Андреев,Андрей,1000,564897684,Менеджер;Олен,Сергей,1992,564897684,Менеджер;Гаара,Петр,1992,564897684,Менеджер;Псо,Анли,5643,6846163584,Отдел Продаж;