-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
executable file
·255 lines (211 loc) · 6.52 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# Copyright 2016 Eduardo Frazão ( https://github.com/fr4z40 )
#
# Licensed under the MIT License;
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://opensource.org/licenses/MIT
#
from pymg_pkg import *
from subprocess import call
from os import path
try:
import readline
except:
pass
how_to = '''
#
# Mode Options
#
# - help
# --- Show This Help.
#
# - exit
# --- exit the software.
#
# - files
# --- Search in Files/Folders.
# --- You can set a file or a folder to Search.
#
# - url
# --- Search in a single page.
#
# - google
# --- Search using Google.
#
# - add_filter
# --- set an external file as an adtional filter.
# --- you can use a file with emails, to not repeat those emails.
# ( "Items" in that file are separated by lines, espaces and tabulations )
#
'''
def log(pth_name, cntd):
out_file = open(pth_name, 'a')
out_file.write('%s\n' % cntd.strip())
out_file.close()
def help_module():
print(how_to)
def add_filter():
f_p = None
while (f_p==None):
filter_file = input("* Set Here your adtional filter\n:")
filter_file = ((str(filter_file)).strip()).strip("'")
if path.isfile(filter_file):
filter_in = open(filter_file, 'r')
cnt = (filter_in.read()).strip().split()
filter_in.close()
global f_p
f_p = cnt
break
else:
print("It's not a file, please, try again\n")
def file_module():
tgt = None
while (tgt==None):
try:
tgt = input("* Set Target path\n- You can type the full path\n- or drag the folder/file to here.\n:")
tgt = ((str(tgt)).strip()).strip("'")
if (path.isdir(tgt) or path.isfile(tgt)):
break
else:
tgt = None
print("Path Error, please, try again\n")
except Exception as err:
if err == KeyboardInterrupt:
quit()
else:
pass
search_on_file(tgt, out_f, filter_plus=f_p)
def url_module():
tgt_url = None
while (tgt_url==None):
try:
tgt_url = input("* Set Target URL\n:")
tgt_url = ((str(tgt_url)).strip()).strip("'")
if 'http' not in tgt_url:
tgt_url = ('http://'+tgt_url)
if (len(tgt_url) >= 5):
break
else:
tgt_url = None
print("Error, please, try again\n")
except Exception as err:
if err == KeyboardInterrupt:
quit()
else:
pass
rst = search_on_page(tgt_url, filter_plus=f_p)
rst.sort()
rst = ('\n'.join(rst))
log(out_f, rst)
def google_module():
try:
# search key
s_keys = None
while (s_keys==None):
s_keys = input("* Set Keys to search\n:")
s_keys = ((str(s_keys)).strip())
if (len(s_keys) >= 5):
break
else:
s_keys = None
print("too short")
print("\n- Key: %s\n\n" % s_keys)
# "stop" argument
condition = False
while (condition==False):
print("* When Stop?\n* Set a page limit\n* Default is 10, just type enter.")
print('* Or Type None to "unlimit", only will stop with CTRL+C')
stop_arg = ((input(":")).strip()).lower()
if len(stop_arg) == 0:
condition = True
stop_arg = 10
break
elif str.isdigit(stop_arg):
stop_arg = int(stop_arg)
condition = True
break
elif (str.isalpha(stop_arg) and (stop_arg.lower() == "None")):
stop_arg = None
condition = True
break
else:
print("Try again...\n")
print("\n- Stop: %s\n\n" % stop_arg)
# "pause" argument
condition = False
while (condition==False):
print('* Set a "Delay"\n* Default is 5, just type enter.')
pause_arg = ((input(":")).strip()).lower()
try:
pause_arg = float(pause_arg)
condition = True
break
except:
if len(pause_arg) == 0:
condition = True
pause_arg = 5
break
else:
print("Try again...\n")
print("\n- Pause: %s\n\n" % pause_arg)
from pymg_pkg.g_search import search as g_search
for lnk in g_search(s_keys, stop=stop_arg, pause=pause_arg):
print("Working on: %s" % lnk)
rst = search_on_page(lnk, filter_plus=f_p)
rst.sort()
rst = ('\n'.join(rst)).strip()
log(out_f, rst)
except Exception as err:
if err == KeyboardInterrupt:
quit()
else:
pass
def main():
call('reset')
options = {
'help':help_module,
'files':file_module,
'url':url_module,
'google':google_module,
'add_filter':add_filter
}
print(' Copyright 2016 Eduardo Frazão ( https://github.com/fr4z40 )')
print(' enter "help" any time if necessary.\n')
print("Mode Selection")
while 1:
ent = ((str(input("~>"))).strip()).lower()
if ('exit' not in ent):
try:
options[ent]()
except Exception as err:
print(err)
if (len(ent) >= 1):
print("Error!")
pass
else:
quit()
if __name__ == '__main__':
global f_p
f_p=None
call('reset')
out_f = None
while (out_f==None):
try:
out_f = input("* Set output file path\n:")
out_f = ((str(out_f)).strip()).strip("'")
# write_test
if ((path.exists(out_f) == False) and (len(out_f)>=5)):
(open(out_f, 'w')).close()
else:
out_f = None
raise(Exception)
except Exception as err:
if err == KeyboardInterrupt:
quit()
else:
pass
main()