This repository has been archived by the owner on Jul 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
75 lines (56 loc) · 1.97 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
from fbs_runtime.application_context.PyQt5 import ApplicationContext
from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox
from PyQt5 import uic
from os import path
from PyPDF2 import PdfFileReader as PdfReader
import os
import csv
import sys
def read_pdf(root_folder, sources):
results = []
counter_pages = 0
for source in sources:
counter = PdfReader(source.get('path')).getNumPages()
results.append([source.get('path'), source.get('file'), counter])
counter_pages += counter
results.append(['Total de paginas: ' + str(counter_pages)])
write(os.path.join(root_folder, 'results.csv'), results)
def write(csv_location, items):
with open(csv_location, 'w', newline='') as file:
writer = csv.writer(file)
for i in items:
writer.writerow(i)
show_dialog('Alerta', 'El proceso a terminado.')
def show_dialog(title, message):
msg_box = QMessageBox()
msg_box.setIcon(QMessageBox.Information)
msg_box.setText(message)
msg_box.setWindowTitle(title)
msg_box.show()
msg_box.exec()
def search_files_in_directory(root_path, extension):
sources = []
for root, dirs, files in os.walk(root_path):
for file in files:
if file.endswith(extension):
sources.append(
{'path': os.path.join(root, file), 'file': file})
read_pdf(root_path, sources)
class MainGUI(QMainWindow):
def __init__(self):
super().__init__()
uic.loadUi('main.ui', self)
self.comenzar.clicked.connect(self.start)
def start(self):
user_path = self.folder.toPlainText()
if path.exists(user_path):
search_files_in_directory(user_path, '.pdf')
else:
show_dialog('Alerta', 'El directorio no existe')
if __name__ == '__main__':
appctxt = ApplicationContext()
window = MainGUI()
window.resize(500, 150)
window.show()
exit_code = appctxt.app.exec_()
sys.exit(exit_code)