-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
67 lines (43 loc) · 1.61 KB
/
run.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
import os
import re
searchConfig = {
"rootPath": "C:\\HirakSantra\\Node js",
"fileExtension": ".txt",
"search": "Hirak|Santra|I am the don"
}
class HiSearch:
def __init__(self):
self.file_store = []
self.search_store = []
self.extension = searchConfig.get('fileExtension')
self.search_word = searchConfig.get('search')
def is_match_found(self, text):
word_list = self.search_word.split('|')
for word in word_list:
x = re.search(word, text)
if x is not None:
return True
return False
def find(self, path=searchConfig.get('rootPath')):
for obj in os.listdir(path):
f_path = os.path.join(path, obj)
if os.path.isdir(f_path):
self.find(f_path)
elif obj.endswith(self.extension):
self.file_store.append(f_path)
with open( f_path, "r") as fd:
content = fd.read()
if self.is_match_found(content):
self.search_store.append({
"content": content,
"path": f_path
})
def print_match_files(self):
print(self.search_store)
def print_all_same_type_files(self):
print(self.file_store)
if __name__=='__main__':
searcher = HiSearch()
searcher.find()
searcher.print_all_same_type_files();
searcher.print_match_files();