diff --git a/crawler.py b/crawler.py index 111a6ab..51cb180 100644 --- a/crawler.py +++ b/crawler.py @@ -38,6 +38,7 @@ def filteringcon(filters_regex_one): file[i] = re.sub('\s\s+#.*', '', file[i]) file[i] = re.sub(' CNAME .$', '', file[i]) file[i] = re.sub(' CNAME . $', '', file[i]) + file[i] = re.sub('^\*.', '', file[i]) with open(filters_regex_one, 'w') as f1: f1.writelines(["%s\n" % item for item in file]) print("++ successful!") @@ -48,7 +49,7 @@ def filteringcon(filters_regex_one): with open(filters_regex_one, 'r') as f: for line in f: for word in a: - if word in line and not line.startswith('#') and line.startswith((tuple(a))): + if word in line and not line.startswith('#') and line.startswith((tuple(a))) and not '.' in line: line = line.replace(word,'') else: line = line.replace(line, line) diff --git a/maker_abp.py b/maker_abp.py new file mode 100644 index 0000000..e9f9fe9 --- /dev/null +++ b/maker_abp.py @@ -0,0 +1,32 @@ +import datetime +import pytz + +UTC = pytz.utc +date = datetime.datetime.now(UTC) + +def linecounter(incoming): + with open(incoming) as f: + for i, l in enumerate(f): + pass + return i + 1 + +def ABPbuilding(excluded,incoming,output): + ankstanop = linecounter(incoming) + with open(excluded ,'r') as f: + exclude = f.read().split() + with open(incoming ,'r') as f: + lines = f.read().splitlines() # read lines + with open(output ,'w') as f: + f.write('! Title : Minoplhy Personal Blocklist\n') + f.write('! Description : My Very Personal DNS Blocklist plus crawling from the source\n') + f.write('! Source : Resources/Source.txt\n') + f.write('! Rule Counter : ' + str(ankstanop) +' Rules\n') + f.write('! Format : AdblockPlus\n') + f.write('! Licenses : MIT\n') + f.write('! Compiled Date : ' + str(date) +'\n\n') + for line in lines: + if line.strip() and not line in exclude and not line.startswith(';'): + f.write('\n'.join(['||' + line + '^ \n'])) + elif line.startswith((';','$','@',' IN')): + f.write('\n'.join([line + '\n'])) + f.close() \ No newline at end of file diff --git a/maker_rpz.py b/maker_rpz.py index 40c6c38..d3080da 100644 --- a/maker_rpz.py +++ b/maker_rpz.py @@ -29,9 +29,7 @@ def RPZbuilding(excluded,incoming,output): f.write(' IN NS localhost.\n\n') for line in lines: if line.strip() and not line in exclude and not line.startswith(';'): - f.write('\n'.join([line + ' CNAME .\n'])) + f.write('\n'.join([line + ' CNAME .\n'])) and f.write('\n'.join(['*.'+line+' CNAME .\n'])) elif line.startswith((';','$','@',' IN')): f.write('\n'.join([line + '\n'])) - elif not line.strip(): - f.write('\n'.join([line + '\n'])) f.close() \ No newline at end of file