-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
blocklist
committed
Aug 2, 2024
1 parent
d6c54fc
commit bc0bd9c
Showing
12 changed files
with
94 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,42 @@ | ||
import sys | ||
|
||
def updateLine(line): | ||
line = line.replace('@@', '') | ||
line = line.replace('^', '^$badfilter') | ||
return line | ||
|
||
def checkline(line): | ||
if line.lstrip().startswith("@@"): | ||
return True | ||
|
||
return False | ||
|
||
def overwrite(filename='blocklist.txt'): | ||
with open(filename,'r+') as file: | ||
lines = file.readlines() | ||
count = 0 | ||
for line in lines: | ||
if checkline(line): | ||
lines[count] = updateLine(line) | ||
count = count + 1 | ||
|
||
with open(filename,'w') as wfile: | ||
|
||
from modules.clean import format_record, split_records | ||
|
||
|
||
def badfilter_records(input_records, blocklist_file='blocklist.txt'): | ||
bad_records = split_records(input_records) | ||
|
||
with open(blocklist_file,'r') as f: | ||
formatted_bad_records = [] | ||
lines = [] | ||
|
||
for bad_record in bad_records: | ||
formatted_bad_record = F"{format_record(bad_record)}" | ||
formatted_bad_records.append(formatted_bad_record) | ||
|
||
for record in f.readlines(): | ||
# Remove newline character | ||
record = record.strip('\n') | ||
if record in formatted_bad_records: | ||
lines.append(F"{record}" + '$badfilter') | ||
formatted_bad_records.remove(record) | ||
print(F"{record} marked as badfilter") | ||
else: | ||
lines.append(record) | ||
|
||
for bad_record in formatted_bad_records: | ||
print(F"{bad_record} not been badlisted") | ||
|
||
with open(blocklist_file,'w') as wfile: | ||
for line in lines: | ||
wfile.write(line) | ||
wfile.close() | ||
wfile.write(F"{line}\n") | ||
|
||
|
||
if __name__ == '__main__': | ||
overwrite() | ||
records = sys.argv | ||
records.pop(0) # remove filename from list | ||
if records.__len__() == 0: | ||
print('Set records as badfilter, such as domains, valid adp rules, or full paths to blocklist.txt') | ||
records = input('Enter record(s): ') | ||
badfilter_records(records) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.