-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeepSearch.py
155 lines (125 loc) · 3.49 KB
/
DeepSearch.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
import os
from time import sleep
try:
import docx
from pptx import Presentation
from tkinter import *
from tkinter import messagebox
from tkinter import filedialog
except Exception as e:
print('Requirement Not Satisfied')
print('pip install python-docx')
print('pip install python-pptx')
sleep(10)
quit()
def handleDOCXFile(file, search_key):
doc = docx.Document(file)
pr_no = 1
location = 'Line : '
flag = False
for line in doc.paragraphs:
if search_key in line.text.lower():
flag = True
# print('Found at Paragraph:', pr_no)
# print(line.text)
location += str(pr_no)+' '
pr_no += 1
if flag:
return True, location
return False, ''
def handlePPTXFile(file, search_key):
prs = Presentation(file)
slide_no = 1
location = 'Slide: '
flag = False
for slide in prs.slides:
for shapes in slide.shapes:
if shapes.has_text_frame:
# print(shapes.text)
if(search_key in shapes.text.lower()):
flag = True
# print('Found at Slide', slide_no)
location += str(slide_no) + ' '
break
slide_no += 1
if flag:
return True, location
return False, ''
def handleOtherFiles(file, search_key):
line_no=1
location = 'Line : '
flag = False
with open(file, 'r') as f:
for line in f:
if search_key in line.lower():
flag = True
# print(file,'Line', line_no)
location += str(line_no) + ' '
line_no += 1
if flag:
return True, location
return False, ''
def clearlist():
resultList.delete(0, END)
anotherList.delete(0, END)
i = 1
path = 'No Directory Choosen'
def getFiles():
clearlist()
global i, path
# extensions = ['.pptx']
extensions = ['.txt', '.py', '.docx', '.pptx', '.cpp']
search_key = searchBox.get().lower()
if path == 'No Directory Choosen':
messagebox.showinfo("Error", "Choose the Directory")
return
if search_key == '':
messagebox.showinfo("Invalid", "Enter in the Search Box")
return
flag = False
os.chdir(path+'/')
for file in os.listdir():
f_name, f_ext = os.path.splitext(file)
status = False
location = 'None'
if f_ext!='' and f_ext in extensions:
if f_ext=='.docx':
status, location = handleDOCXFile(file, search_key)
elif f_ext=='.pptx':
status, location = handlePPTXFile(file, search_key)
else:
status, location = handleOtherFiles(file, search_key)
if(status):
resultList.insert(i, file)
anotherList.insert(i, location)
flag = True
i += 1
if flag==False:
messagebox.showinfo("Result", "Nothing Match")
i = 1
def chooseDirectory():
global path
path = filedialog.askdirectory()
if path == '':
path = 'No Directory Choosen'
fileLabel.configure(text=path)
root = Tk()
root.title('Deep Finder')
root.geometry('1000x500')
header = Label(root, text='Deep Finder', font=('Arial', 20), fg='red')
header.pack(pady=20)
searchBox = Entry(root, width=50, bd=2, font=('Arial', 18), justify='center', fg='gray') #searchBox.get()
searchBox.pack()
fileLabel = Label(root, text=path, font=('Arial', 10), fg='black')
fileLabel.pack()
browseBtn = Button(root, text='Browse', width=10, command=chooseDirectory)
browseBtn.pack(pady=10)
findBtn = Button(root, text='Find', width=10, command=getFiles, fg='white', bg='green')
findBtn.pack(pady=20)
frame = Frame(root)
frame.pack()
resultList = Listbox(frame, width=50)
resultList.grid(row=0, column=0)
anotherList = Listbox(frame, width=50)
anotherList.grid(row=0, column=1)
root.mainloop()