From 8e88bbbb7d8d03c0efd7efd44cd428e277950c3b Mon Sep 17 00:00:00 2001 From: minoplhy Date: Tue, 10 Aug 2021 13:08:01 +0700 Subject: [PATCH] excluder modules : add remove Modules and add search module Add remove and remove_file support for removing domains from file Add search support for search domains and it all subdomain Fix confusion on input --- excluder.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/excluder.py b/excluder.py index 34d9f77..ade0794 100644 --- a/excluder.py +++ b/excluder.py @@ -1,11 +1,11 @@ import os import crawler -def add(incoming,input): +def add(incoming,userinput): with open(incoming, 'r') as f: lines = f.read().split() with open(incoming, 'a') as f: - f.write('\n'.join([input + '\n'])) + f.write('\n'.join([userinput + '\n'])) with open(incoming, 'r') as f: lines = set(f.readlines()) with open(incoming, 'w') as f: @@ -28,14 +28,14 @@ def add_file(incoming,excluded_in): crawler.sort(incoming) os.remove(excluded_in) -def remove(incoming,input): +def remove(incoming,userinput): with open(incoming, 'r') as f: lines = f.read().split() with open(incoming, 'w') as f: for line in lines: - if line.startswith(input) and input in line: - f.write(line.replace(input ,'')) - elif not line.startswith(input): + if line.startswith(userinput) and userinput in line: + f.write(line.replace(userinput ,'')) + elif not line.startswith(userinput): f.write('\n'.join([line + '\n'])) with open(incoming ,'r') as f: lines = f.read().split() @@ -47,4 +47,26 @@ def remove(incoming,input): lines = set(f.readlines()) with open(incoming, 'w') as f: f.writelines(set(lines)) - crawler.sort(incoming) \ No newline at end of file + crawler.sort(incoming) + +def remove_file(incoming ,removed_in): + with open(removed_in ,'r') as f: + stallin = f.read().split() + with open(incoming, 'r') as f: + lines = f.read().split() + with open(incoming, 'w') as f: + for line in lines: + if line in stallin and line.strip() and line.startswith((tuple(stallin))): + f.write(line.replace(line ,'')) + elif not line.startswith((tuple(stallin))): + f.write('\n'.join([line + '\n'])) + os.remove(removed_in) + +def search(incoming,userinput): + + with open(incoming, 'r') as f: + lines = f.read().split() + for line in lines: + if userinput in line and line.endswith(userinput): + print(line) + \ No newline at end of file