From c779dc4b96e10e53b82919ded434a46c9512249d Mon Sep 17 00:00:00 2001 From: Nick Spaargaren Date: Mon, 1 May 2023 21:39:33 +0200 Subject: [PATCH] Add AdGuard important list (#172) * Add adguard-important list command * Add adguard-important list command to github workflow --- .github/workflows/automated-updates.yml | 3 ++- convert.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/automated-updates.yml b/.github/workflows/automated-updates.yml index 40afb7e..62c6507 100644 --- a/.github/workflows/automated-updates.yml +++ b/.github/workflows/automated-updates.yml @@ -20,9 +20,10 @@ jobs: - name: Update categories run: | python3 convert.py categories - - name: Update AdGuard list + - name: Update AdGuard lists run: | python3 convert.py adguard + python3 convert.py adguard-important - name: Update parsed list run: | python3 convert.py pihole diff --git a/convert.py b/convert.py index a757013..3228334 100644 --- a/convert.py +++ b/convert.py @@ -12,6 +12,7 @@ class DomainBlocklistConverter: PIHOLE_FILE = "google-domains" UNBOUND_FILE = "pihole-google-unbound.conf" ADGUARD_FILE = "pihole-google-adguard.txt" + ADGUARD_IMPORTANT_FILE = "pihole-google-adguard-important.txt" CATEGORIES_PATH = "categories" BLOCKLIST_ABOUT = "This blocklist helps to restrict access to Google and its domains. Contribute at https://github.com/nickspaargaren/no-google" @@ -83,6 +84,19 @@ class DomainBlocklistConverter: if entry != "": f.write(f"||{entry}^\n") + def adguard_important(self): + """ + Produce blocklist for AdGuard including important syntax. + """ + with open(self.ADGUARD_IMPORTANT_FILE, "w") as f: + f.write(f"! {self.BLOCKLIST_ABOUT}\n") + f.write(f"! Last updated: {self.timestamp}\n") + for category, entries in self.data.items(): + f.write(f"! {category}\n") + for entry in entries: + if entry != "": + f.write(f"||{entry}^$important\n") + def categories(self): """ Produce individual per-category blocklist files. @@ -163,7 +177,7 @@ def run(action: str): if __name__ == "__main__": # Read subcommand from command line, with error handling. - action_candidates = ["pihole", "unbound", "adguard", "categories"] + action_candidates = ["pihole", "unbound", "adguard", "adguard_important", "categories"] special_candidates = ["all", "duplicates", "json"] subcommand = None try: