-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
192 lines (149 loc) · 6.98 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
from tkinter import filedialog
import tkinter as tk
import pandas as pd
import openpyxl
import itertools
# Переменные для записи данных
Namber_Acts, Data_Acts, Named_work, IS, materials = [], [], [], [], []
""" модуль: работа с файлами"""
def open_read_files():
# Открываем файл чтения
file_path_o = filedialog.askopenfilename()
print('Открываем файл чтения', file_path_o)
return file_path_o
def open_file_write():
# Открываем файл записи
file_path_w = filedialog.askopenfilename()
print('Открываем файл записи', file_path_w)
return file_path_w
def read_files(file_path_o):
# Читаем данные
path_file_read_and_write_excel = file_path_o
return path_file_read_and_write_excel
def open_book_write(file_path_w):
# Открываем книгу для записи данных
path_file_write_excel = file_path_w
workbook = openpyxl.load_workbook(path_file_write_excel)
return workbook
def reading_data(path_file_read_and_write_excel):
# читаем лист
df = pd.read_excel(path_file_read_and_write_excel, sheet_name='БД (5)')
return df
def open_list_write(workbook):
# выбираем лист, в который будем записывать значения
worksheet = workbook['Реестр']
return worksheet
def show_sheet(sheet_name, root):
# Функция, которая будет вызываться при нажатии на кнопку листа
print(f"Имя выбранного листа: {sheet_name}")
root.destroy()
def get_sheet_name():
# Открытие книги Excel
wb = openpyxl.load_workbook('/Users/gregoryreyn/Desktop/Общая БД 2.xlsm')
# Создание окна с кнопками листов
root = tk.Tk()
root.title("Выберите лист")
for i, sheet in enumerate(wb.sheetnames):
# Создание кнопки с именем листа
btn = tk.Button(root, text=sheet, command=lambda sheet_name=sheet: show_sheet(sheet_name, root))
btn.grid(row=0, column=i)
root.mainloop()
return root
""" модуль: логика"""
def parsing_data(df):
# парсим и записываем данные в переменные
for index, row in df.iterrows():
Namber_Acts.append(row['№ акта'])
Data_Acts.append(row['дата акта'])
Named_work.append(row['1. К освидетельствованию предъявлены следующие работы:'])
IS.append(row['4. Предъявлены документы'])
materials.append(row['3. При выполнении работ применены:'])
def act_gen():
# генерируем акты
aosr, act_namber, act_name_work = 'АОСР', Namber_Acts, Named_work
finel_act = []
for i in range(len(act_name_work)):
finel_act.append(f"{aosr} {act_namber[i]} {act_name_work[i]}")
return finel_act
def is_gen():
# генерируем схемы (разделяем схемы)
my_list1 = IS
finel_IS = []
for item in my_list1:
split_str = item.split(";")
finel_IS += [x.strip() for x in split_str]
return finel_IS
def materials_gen():
# генерируем паспорта/сертификаты (разделяем паспорта/сертификаты)
materials_list = materials
finel_materials = [materials]
for item in materials_list:
split_str = item.split(";")
finel_materials += [x.strip() for x in split_str]
pass
def osi_gen(finel_act):
finel_osi_otm = [] # новый список, куда будут записываться значения
for item in finel_act:
if "в осях" in item:
new_item = item.split("в осях", 1)[1].strip()
finel_osi_otm.append("в осях " + new_item)
return finel_osi_otm
def all_write(file_path_w, worksheet, workbook, finel_act, finel_IS, finel_osi_otm):
starting_row = 12 # определяем ячейку, с которой начнём записывать значения
starting_column = 3
for write_finel_act, write_finel_IS, write_finel_materials, write_data_Acts, write_finel_osi_otm in itertools.zip_longest(
finel_act, finel_IS, materials, Data_Acts, finel_osi_otm, fillvalue="-"):
worksheet.cell(row=starting_row, column=starting_column, value=write_finel_act)
worksheet.cell(row=starting_row, column=starting_column + 1, value=write_finel_osi_otm)
worksheet.cell(row=starting_row, column=starting_column + 2, value=write_data_Acts)
worksheet.cell(row=starting_row + 1, column=starting_column, value=write_finel_IS)
worksheet.cell(row=starting_row + 2, column=starting_column, value=write_finel_materials)
starting_row += 3
workbook_save = workbook.save(file_path_w)
# Проверка финальных данных
print('финальные акты:', finel_act)
print('Дата акта:', Data_Acts)
print('финальные оси и отметки:', finel_osi_otm)
print('финальые Исполнительные схемы:', finel_IS)
print('материалы:', materials)
return workbook_save
""" модуль: запуск"""
def main():
# вызываем функцию open_read_files()
file_path_o = open_read_files()
# вызываем функцию open_file_write()
file_path_w = open_file_write()
# вызываем функцию read_files()
path_file_read_and_write_excel = read_files(file_path_o)
# вызываем функцию open_book_write()
workbook = open_book_write(file_path_w)
# вызываем функцию reading_data()
df = reading_data(path_file_read_and_write_excel)
# вызываем функцию open_list_write()
worksheet = open_list_write(workbook)
# вызываем функцию parsing_data()
parsing_data(df)
# вызываем функцию act_gen()
finel_act = act_gen()
# вызываем функцию is_gen()
finel_IS = is_gen()
# вызываем функцию materials_gen()
materials_gen()
# вызываем функцию osi_gen()
finel_osi_otm = osi_gen(finel_act)
# вызываем функцию all_write()
all_write(file_path_w, worksheet, workbook, finel_act, finel_IS, finel_osi_otm)
""" модуль: интерфейс"""
def button():
root = tk.Tk()
root.title("кря")
button1 = tk.Button(root, text="Открыть файл чтения", command='')
button1.pack()
button2 = tk.Button(root, text="Открыть файл записи", command='')
button2.pack()
button3 = tk.Button(root, text="запись", command=lambda: main())
button3.pack()
button3 = tk.Button(root, text="проверка кнопок", command=get_sheet_name)
button3.pack()
root.mainloop()
button()