|
1 | 1 | import zipfile, re, os, sys, resources.checks as checks
|
2 | 2 | from resources.updatezip import UpdateableZipFile as uzip
|
3 |
| -from tkinter.filedialog import askopenfilename, askopenfile, askdirectory |
| 3 | +from tkinter.filedialog import askopenfilenames, askdirectory |
4 | 4 | from tkinter import Tk
|
5 | 5 |
|
6 |
| -file = not sys.argv.__contains__('--dir') |
| 6 | +files = not sys.argv.__contains__('--dir') |
7 | 7 | cli = sys.argv.__contains__('--cli')
|
8 |
| -filepath, folderpath = '','' |
| 8 | +filepaths, folderpath = [],'' |
9 | 9 |
|
10 | 10 | if not cli: Tk().withdraw()
|
11 | 11 |
|
12 | 12 | # input
|
13 |
| -if file: |
14 |
| - filepath = askopenfilename() if not cli else input('Enter the path to the xlsx file. Both explicit and relative are valid.\n') |
| 13 | +if files: |
| 14 | + if not cli: |
| 15 | + filepaths = list(askopenfilenames(filetypes = [('excel files', '.xlsx')])) |
| 16 | + else: |
| 17 | + filepaths.append(input('Enter the path to the xlsx file. Both explicit and relative are valid.\n')) |
15 | 18 | else:
|
16 | 19 | folderpath = askdirectory() if not cli else input('Enter the path to the target directory. Both explicit and relative are valid.\n')
|
17 | 20 |
|
|
20 | 23 |
|
21 | 24 | def processfile(excelfile):
|
22 | 25 | sheetfiles = {}
|
23 |
| - |
24 | 26 | # get all target sheet paths
|
25 | 27 | with zipfile.ZipFile(excelfile) as zip:
|
26 | 28 | for filename in zip.namelist():
|
27 | 29 | if filename.startswith('xl/worksheets/sheet') and filename.endswith('.xml'):
|
28 | 30 | ofile = zip.open(filename)
|
29 | 31 | sheetfiles[filename] = re.sub(strclean, '', ofile.read().decode('utf-8'))
|
30 |
| - |
31 | 32 | # alter files
|
32 | 33 | with uzip(excelfile) as file:
|
33 | 34 | for fname, fcontent in sheetfiles.items():
|
34 | 35 | file.writestr(fname, fcontent.encode('utf-8'))
|
35 | 36 |
|
36 | 37 | # execute
|
37 |
| -if file: |
38 |
| - if checks.checkfile(filepath): |
39 |
| - processfile(filepath) |
| 38 | +if files: |
| 39 | + if checks.checkfiles(filepaths): |
| 40 | + for filepath in filepaths: |
| 41 | + processfile(filepath) |
40 | 42 | print('\033[92mFinished.\033[0m')
|
41 | 43 | else:
|
42 | 44 | if checks.checkpath(folderpath):
|
|
0 commit comments