-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMain.py
executable file
·333 lines (302 loc) · 11.7 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
import lexEngine.lexengine as LE
import os
import time
import subprocess
import client as cli
import translate
import expander
subprocess.call('clear')
print '''
`
`'+++++. '+'+ `'+`+++. :+ +,++++++'`
''++++++++ .++: ;++ .+: ++` `+ ,+' `++
++++++++++'. .++' +'+ ++ `++: :+ :+: ;+,
'+'+++++++++, :+++ ;+++ ++ +:++ +; ;+, '+.
`++'++. ;+'` :+,+ +`++ ++ + '+ + '+. ,++
;++++ ;; ` ;'`+'`,+ ++ '+ ,' '+`,+ ''+++;
++++ `` ,` '; +' +, +' ;+.+. .+,'; ++ ++.
+'+ +++' ,:` +: ++`+ +' ,+:+ +'+` ++ .++
++ #++' ,::` +, .++: `+; `++' +++ ++ #+`
# ` `.` .:::` +. `'+` .+: ++ '+' ++ .'+
, `: ,:::: +` +' :+, #+ :+, `++ +#
:::` ,::::,
::::::::::::`
:::::::::::.
.:::::::::.
`::::::,`
`
Presents :
'''
print '''
$$\ $$\ $$\ $$\ $$\ $$\
$$ | $\ $$ | $$ |$$ | $$ | $$ |
$$ |$$$\ $$ | $$$$$$\ $$$$$$\ $$$$$$$ |$$ | $$ | $$$$$$\ $$\ $$\ $$$$$$$\ $$$$$$$ |
$$ $$ $$\$$ |$$ __$$\ $$ __$$\ $$ __$$ |$$$$$$$$ |$$ __$$\ $$ | $$ |$$ __$$\ $$ __$$ |
$$$$ _$$$$ |$$ / $$ |$$ | \__|$$ / $$ |$$ __$$ |$$ / $$ |$$ | $$ |$$ | $$ |$$ / $$ |
$$$ / \$$$ |$$ | $$ |$$ | $$ | $$ |$$ | $$ |$$ | $$ |$$ | $$ |$$ | $$ |$$ | $$ |
$$ / \$$ |\$$$$$$ |$$ | \$$$$$$$ |$$ | $$ |\$$$$$$ |\$$$$$$ |$$ | $$ |\$$$$$$$ |
\__/ \__| \______/ \__| \_______|\__| \__| \______/ \______/ \__| \__| \_______|
'''
time.sleep(2)
def main():
while True:
subprocess.call("clear")
print '''
=== WELCOME TO WORDHOUND ===
[+] Please select option:
1. Generate Dictionary
2. Expand or Translate Existing dictionary
99. Exit
'''
choice = int(raw_input())
if choice == 1:
generation()
elif choice == 2:
manipulate()
else:
return
def manipulate():
os.system("clear")
print '''
[+] Please select option:
1. Translate Dictionary
2. Expand Dictionary (Tries to derive keywords from related terms)
'''
choice = int(raw_input())
if choice == 1:
translateDict()
else:
expand()
def expand():
print '[+] Please input the location of dictionary'
loc = raw_input().replace("\'", "").strip()
while not(os.path.exists(loc)):
print "[x] {0} doesn't seem to exist, try again.".format(loc)
loc = raw_input()
print "[-] Beginning Expansion..."
e = expander.expand(loc, loc+"-EXPANDED")
e.expand()
def translateDict():
print '[+] Please input the location of dictionary'
loc =raw_input().replace("\'", "").replace("\"", "").strip()
while not(os.path.exists(loc.replace("\'", "".replace("\"", "")))):
print "[x] That doesn't seem to exist, try again."
loc = raw_input()
f = open('languages.data', 'r')
x = f.readlines()
choices = x[:]
f.close()
for i in range(len(x)):
print "\t{0}. {1}".format(i,x[i].split('\t')[0])
print "[+] Please select the language to translate to (e.g. 12):"
choice = int(raw_input())
lang = choices[choice].split('\t')[1]
t = translate.Translator(lang.strip())
f = open(loc, 'r')
x = f.read()
f.close()
translated = t.translate(x)
f = open(loc+"-{0}".format(lang.upper()).strip(), 'w')
f.write(translated.encode('utf8'))
f.close()
print "[+] Dictionary translated, saved to {0}...".format(loc+"-{0}".format(lang.upper()))
raw_input()
os.system("clear")
def generation():
string, options = createJob()
print '''
=== WELCOME TO WORDHOUND ===
[+] Please select industry:
'''
print string
print "\t99. Exit"
choice = int(raw_input())-1
if choice == 98:
subprocess.call('clear')
print "[-] Thanks for using *WordHound*.\n\t@tehnlulz"
return
if choice >= len(options):
createNewIndustry()
else:
industrySelected(options[choice])
print "Press enter to continue..."
raw_input()
def industrySelected(industry):
subprocess.call("clear")
count = 1
options = ""
print'''
=== {0} ==='''.format(industry)
optionsList = []
#print(returnDirs("data/industries/"+industry+'/'))
for dirname in returnDirs("data/industries/"+industry+'/'):
options += '\t'+str(count) + ". " + dirname + '\n'
optionsList.append(dirname)
count+=1
options += '\n\t'+str(count) + ". Create new client\n"
options += '\t'+str(count+1) + ". Generate industry correlated dictionary\n"
options += '\t'+str(count+2) + ". Generate concatenated industry dictionary\n"
print options
choice = int(raw_input())
if choice == count:
createNewClient(industry)
elif choice == (count+1):
generateIndustryDictionary(industry)
elif choice == (count+2):
generateCollatedDictionary(industry)
else:
clientSelected(optionsList[choice-1], industry)
def generateCollatedDictionary(industry):
currInds = []
for dirname in returnDirs("data/industries/"+industry+'/'):
if os.path.exists("data/industries/"+industry+'/'+dirname+'/'+"PdfDictionary.txt"):
currInds.append("data/industries/"+industry+'/'+dirname+'/'+"PdfDictionary.txt")
if os.path.exists("data/industries/"+industry+'/'+dirname+'/'+"WebsiteDictionary.txt"):
currInds.append("data/industries/"+industry+'/'+dirname+'/'+"WebsiteDictionary.txt")
if os.path.exists("data/industries/"+industry+'/'+dirname+'/'+"TxtDictionary.txt"):
currInds.append("data/industries/"+industry+'/'+dirname+'/'+"TxtDictionary.txt")
if os.path.exists("data/industries/"+industry+'/'+dirname+'/'+"TwitterSearchTermDictionary.txt"):
currInds.append("data/industries/"+industry+'/'+dirname+'/'+"TwitterSearchTermDictionary.txt")
if os.path.exists("data/industries/"+industry+'/'+dirname+'/'+"TwitterHandleDictionary.txt"):
currInds.append("data/industries/"+industry+'/'+dirname+'/'+"TwitterHandleDictionary.txt")
lex = LE.lexengine("", "data/industries/"+industry+'/'+"CollatedDictionary.txt", False)
print "[+] Beginning dictionary collation..."
lex.collateDicts(currInds)
print ""
def generateIndustryDictionary(industry):
currInds = []
for dirname in returnDirs("data/industries/"+industry+'/'):
if os.path.exists("data/industries/"+industry+'/'+dirname+'/'+"PdfDictionary.txt"):
currInds.append("data/industries/"+industry+'/'+dirname+'/'+"PdfDictionary.txt")
if os.path.exists("data/industries/"+industry+'/'+dirname+'/'+"WebsiteDictionary.txt"):
currInds.append("data/industries/"+industry+'/'+dirname+'/'+"WebsiteDictionary.txt")
if os.path.exists("data/industries/"+industry+'/'+dirname+'/'+"TxtDictionary.txt"):
currInds.append("data/industries/"+industry+'/'+dirname+'/'+"TxtDictionary.txt")
if os.path.exists("data/industries/"+industry+'/'+dirname+'/'+"TwitterSearchTermDictionary.txt"):
currInds.append("data/industries/"+industry+'/'+dirname+'/'+"TwitterSearchTermDictionary.txt")
if os.path.exists("data/industries/"+industry+'/'+dirname+'/'+"TwitterHandleDictionary.txt"):
currInds.append("data/industries/"+industry+'/'+dirname+'/'+"TwitterHandleDictionary.txt")
lex = LE.lexengine("", "data/industries/"+industry+'/'+"IndustryDictionary.txt", False)
print "[+] Beginning dictionary aggregation..."
lex.aggregateDict(currInds)
print ""
def generateClientDictionary(clientName):
currDicts = []
if os.path.exists(client.workingDirectory + 'PdfDictionary.txt'):
currDicts.append("data/industries/"+industry+'/'+dirname+'/'+"PdfDictionary.txt")
if os.path.exists(client.workingDirectory + 'TxtDictionary.txt'):
currDicts.append("data/industries/"+industry+'/'+dirname+'/'+"TxtDictionary.txt")
if os.path.exists(client.workingDirectory + 'WebsiteDictionary.txt'):
currDicts.append("data/industries/"+industry+'/'+dirname+'/'+"WebsiteDictionary.txt")
if os.path.exists(client.workingDirectory + 'TwitterHandleDictionary.txt'):
currDicts.append("data/industries/"+industry+'/'+dirname+'/'+"TwitterHandleDictionary.txt")
if os.path.exists(client.workingDirectory + 'TwitterSearchTermDictionary.txt'):
currDicts.append("data/industries/"+industry+'/'+dirname+'/'+"TwitterSearchTermDictionary.txt")
def returnDirs(path):
results = []
for (dirpath, dirnames, filenames) in os.walk(path):
results.extend(dirnames)
return results
def clientSelected(clientName, industry):
subprocess.call("clear")
c = cli.client(industry, "", clientName, "", "data/industries/" + industry +'/' + clientName +'/')
newClientOptions(c)
pass
def createNewClient(industry):
subprocess.call("clear")
print'''
=== CREATE NEW CLIENT ===
'''
name = ""
while len(name) == 0:
print "[+] Please enter client name (can be pseudonym):"
name = raw_input()
c = cli.client(industry, "", name, "", "data/industries/" + industry +'/' + name +'/')
print "[-] New client added..."
time.sleep(1)
newClientOptions(c)
def newClientOptions(client):
subprocess.call("clear")
print'''
=== CLIENT OPTIONS ===
[+] Please choose an option:
'''
print "1. Generate Dictionary from website."
print "2. Generate Dictionary from Text file."
print "3. Generate Dictionary from pdf."
#print "4. Generate Dictionary from twitter handle."
print "4. Generate Dictionary from twitter search term."
print "5. Generate Dictionary from Reddit"
print "\n6. Generate aggregate client dictionary."
choice = 0
while(choice not in ['1', '2', '3', '4', '5','6']):
choice = raw_input()
if choice == '1':
print "[-] Please enter the URL of website to be crawled:"
url = raw_input()
#print "[-] Please enter the domain of client (Put a \'.\' for all links):"
#domain = raw_input()
print "[-] How many levels of recursion should I crawl? (Default=2):"
client.url = url
client.domain = ""
recursionLevel = raw_input()
client.buildDictionary(int(recursionLevel))
break
elif choice == '2':
print "[-] Please give the path of the text file to process:"
path = raw_input()
client.buildDictionaryText(path)
break
elif choice == '3':
print "[-] Please give the path of the pdf to process:"
path = raw_input()
client.buildDictionaryPdf(path)
break
#elif choice == '4':
# print "[-] Please enter the user's handle(without the '@'):"
# handle = raw_input()
# client.buildDictionaryFromTwitterUsername(handle)
elif choice == '4':
print "[-] Please enter the search term:"
term = raw_input()
client.buildDictionaryFromTwitterSearchTerm(term)
break
elif choice == '5':
print "[-] Please enter any number of subreddits, seperated by a comma\n(e.g. battlefield, netsec, til)"
subs = raw_input().replace(" ","")
subs = subs.split(',')
print ""
subprocess.call("clear")
client.buildDictionaryReddit(subs)
elif choice == '6':
print "[-] Beginning dictionary aggregation"
client.buildAggregate()
break
def createNewIndustry():
subprocess.call("clear")
print'''
=== CREATE NEW INDUSTRY ===
'''
name = ""
while len(name)==0:
print "[+] Please enter industry name:"
name = raw_input()
if not os.path.exists("data/industries/"+name): os.makedirs("data/industries/"+name)
print "[-] New Industry added..."
time.sleep(1)
subprocess.call("clear")
def createJob():
subprocess.call("clear")
count = 1
options = ""
optionsList = []
for (dirpath, dirnames, filenames) in os.walk("data/industries"):
optionsList.extend(dirnames)
break
for i in optionsList:
options += '\t'+str(count) + ". {0}\n".format(i)
count +=1
options += '\n\t'+str(count) + ". Create new industry\n"
#print optionsList
return options, optionsList
main()