-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
69 lines (58 loc) · 1.76 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
import csv
import Feature_extraction as urlfeature
import trainer as tr
def resultwriter(feature, output_dest):
"""docstring for resultwriter"""
flag = True
with open(output_dest, 'wb') as f:
for item in feature:
w = csv.DictWriter(f, item[1].keys())
if flag:
w.writeheader()
flag = False
w.writerow(item[1])
def process_URL_list(file_dest, output_dest):
"""docstring for process_URL_list"""
feature = []
with open(file_dest) as file:
for line in file:
url = line.split(',')[0].strip()
malicious_bool = line.split(',')[1].strip()
if url != '':
# show off
print 'working on: ' + url
ret_dict = urlfeature.feature_extract(url)
ret_dict['malicious'] = malicious_bool
feature.append([url, ret_dict])
resultwriter(feature, output_dest)
def process_test_list(file_dest, output_dest):
"""docstring for process_test_list"""
feature = []
with open(file_dest) as file:
for line in file:
url = line.strip()
if url != '':
# show off
print 'working on: ' + url
ret_dict = urlfeature.feature_extract(url)
feature.append([url, ret_dict])
resultwriter(feature, output_dest)
# change
def process_test_url(url, output_dest):
"""docstring for process_test_url"""
feature = []
url = url.strip()
if url != '':
# show off
print 'working on: ' + url
ret_dict = urlfeature.feature_extract(url)
feature.append([url, ret_dict])
resultwriter(feature, output_dest)
def main():
"""docstring for main"""
# process_URL_list('URL.txt', 'url_features.csv)
process_test_list('query.txt', 'query_features.csv')
# tr.train('url_features.csv', 'url_features.csv')
# arguments: (input_trainging features, test/query_trainging features)
# testing with urls in query.txt
tr.train('url_features.csv', 'query_features.csv')