From 777857f176522031f2b68b4c5fdd580cb9d07113 Mon Sep 17 00:00:00 2001 From: Steven Black Date: Sat, 12 Jul 2025 22:53:37 -0400 Subject: [PATCH] =?UTF-8?q?Issue=20#2919:=20fix=20=E2=80=94=20look=20for?= =?UTF-8?q?=20a=20file=20named=20post.json=20in=20the=20list=E2=80=99s=20l?= =?UTF-8?q?anding=20folder=20and,=20if=20found,=20parse=20its=20filters=20?= =?UTF-8?q?array=20for=20strings=20to=20exclude=20from=20the=20final=20lis?= =?UTF-8?q?t.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- post.json | 8 ++++++++ updateHostsFile.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 post.json diff --git a/post.json b/post.json new file mode 100644 index 000000000..838ae9f25 --- /dev/null +++ b/post.json @@ -0,0 +1,8 @@ +{ + "filters": [ + "allegro", + "bilet", + "-pl", + "npost" + ] +} diff --git a/updateHostsFile.py b/updateHostsFile.py index a350fe867..6d59fdbb7 100755 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -951,6 +951,17 @@ def remove_dups_and_excl(mergefile, exclusionregexes, outputfile=None): else: finalfile = outputfile + # analyze any post.json here + post_json_path = os.path.join(os.path.dirname(finalfile.name), "post.json") + filters = [] + if os.path.isfile(post_json_path): + try: + with open(post_json_path, "r", encoding="UTF-8") as post_file: + post_data = json.load(post_file) + filters = post_data.get("filters", []) + except Exception as e: + print_failure(f"Error reading post.json: {e}") + mergefile.seek(0) # reset file pointer hostnames = {"localhost", "localhost.localdomain", "local", "broadcasthost"} exclusions = settings["exclusions"] @@ -961,6 +972,10 @@ def remove_dups_and_excl(mergefile, exclusionregexes, outputfile=None): # Explicit encoding line = line.decode("UTF-8") + # Apply post.json filters + if filters and any(f in line for f in filters): + continue + # replace tabs with space line = line.replace("\t+", " ")