-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSearchKey.py
137 lines (134 loc) · 4.08 KB
/
SearchKey.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
from __future__ import print_function
import io
import glob
def SearchKeys(path_file=''):
word = ["Купить", "купить", "КУПИТЬ", "buy", "Buy", "BUY"]
#word="купить"
p={}
sf=[]
try:
with io.open(path_file) as file: #errors='ignore'
for element in word:
for line in file:
if element in line:
p['key']=element
p['path']=path_file
except:
with io.open(path_file, encoding='utf-8') as file: #errors='ignore'
for element in word:
try:
for line in file:
if element in line:
p['key']=element
p['path']=path_file
except UnicodeDecodeError: #return None
continue
except PermissionError:
continue
except FileNotFoundError:
continue
return p
def StartSeachKey(path):
files = glob.glob(path + "\**\*.txt", recursive=True) #txt, xml, ini, lng, lt
files1 = glob.glob(path + "\**\*.ini", recursive=True)
files2 = glob.glob(path + "\**\*.xml", recursive=True) # js map
files3 = glob.glob(path + "\**\*.lng", recursive=True)
files4 = glob.glob(path + "\**\*.lt", recursive=True)
files5 = glob.glob(path + "\**\*.js", recursive=True)
files6 = glob.glob(path + "\**\*.map", recursive=True)
d = []
for element in files:
if len(element) == 0:
continue
try:
n = SearchKeys(element)
except PermissionError:
n = None
try:
if len(n) >=1:
d.append(SearchKeys(element))
except TypeError:
continue
for element in files1:
if len(element) == 0:
continue
try:
n = SearchKeys(element)
except PermissionError:
n = None
try:
if len(n) >=1:
d.append(SearchKeys(element))
except TypeError:
continue
for element in files2:
if len(element) == 0:
continue
try:
n = SearchKeys(element)
except PermissionError:
n = None
try:
if len(n) >=1:
d.append(SearchKeys(element))
except TypeError:
continue
for element in files3:
if len(element) == 0:
continue
try:
n = SearchKeys(element)
except PermissionError:
n = None
try:
if len(n) >=1:
d.append(SearchKeys(element))
except TypeError:
continue
for element in files4:
if len(element) == 0:
continue
try:
n = SearchKeys(element)
except PermissionError:
n = None
try:
if len(n) >=1:
d.append(SearchKeys(element))
except TypeError:
continue
for element in files5:
if len(element) == 0:
continue
try:
n = SearchKeys(element)
except PermissionError:
n = None
try:
if len(n) >=1:
d.append(SearchKeys(element))
except TypeError:
continue
for element in files6:
if len(element) == 0:
continue
try:
n = SearchKeys(element)
except PermissionError:
n = None
try:
if len(n) >=1:
d.append(SearchKeys(element))
except TypeError:
continue
return d
#StartSeachKey("D:\Public\LicenseChecker")
# try:
# tt = StartSeachKey("C:\Program Files\\")
# print(tt)
# except PermissionError:
# print('Ошибка доступа')
#except UnicodeDecodeError:
# print('Ошибка доступа')
#tt = StartSeachKey("C:\\Users\\mrKaban\\AppData\\")
#print(tt)