-
Notifications
You must be signed in to change notification settings - Fork 0
/
skim_reader_io.py
executable file
·72 lines (64 loc) · 2.46 KB
/
skim_reader_io.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
#!/usr/bin/env python3
from typing import List
class SkimReader:
'''
Handle FileIO reads, reading from disks to lists.
'''
def fetch_domain_list(self, dir: str) -> List:
'''
Get the list of domains to scan, from file.
Filter through the whitelist_sieve.
Shuffle and return clean list
'''
try:
import toolbag
import skim_utils
import time
url_list = []
shuf = toolbag.Toolbag().shuffler
dir = str(dir)
apd = url_list.append
lint = skim_utils.SkimUitls().lint
with open(dir, "r") as url_file:
[apd("http://" + str(url)) for url in url_file.read().splitlines()]
url_file.close()
col = toolbag.Toolbag().color
lint(col("Number of domains before whitelisting: " + str(len(url_list)), "yellow"))
time.sleep(.7)
clean_list = self.whitelist_sieve(url_list)
clean_list = shuf(clean_list)
lint(col("Number of domains after whitelisting: " + str(len(clean_list)), "yellow") + "\n\n")
time.sleep(.5)
return clean_list
except Exception as e:
print("Error! in SkimController.fetch_domain_list: " + str(e))
def whitelist_sieve(self, raw_master_list: List) -> List:
'''
Filter whitelisted domains from the list of urls to be processed
'''
try:
import skim_conf
import skim_writer_io
whitelist = skim_conf.Skim_conf().whitelist_domains()
writer = skim_writer_io.Skim_writer_io().writer
clean_master_list = []
apend = clean_master_list.append
in_whitelist = False
for url in raw_master_list:
url = str(url)
for white in whitelist:
white = str(white)
if white in url:
writer(url, "whitelisted")
in_whitelist = True
if in_whitelist == True:
break
if in_whitelist == True:
in_whitelist = False
continue
else:
if url not in clean_master_list:
apend(url)
return clean_master_list
except Exception as e:
print("Error! in SkimController.whitelist_sieve: " + str(e))