From: Charlie Fish Date: Mon, 28 Jun 2021 00:41:14 +0000 (-0600) Subject: Adding script to automate updating number of domains in list X-Git-Tag: aggregated-20250518~537^2~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F348%2Fhead;p=thirdparty%2Fblocklistproject%2Flists.git Adding script to automate updating number of domains in list --- diff --git a/.github/workflows/run-automations.yml b/.github/workflows/run-automations.yml index e594d96..0941aca 100644 --- a/.github/workflows/run-automations.yml +++ b/.github/workflows/run-automations.yml @@ -15,6 +15,7 @@ jobs: node-version: 15.x - run: node scripts/create-everything-list.js - run: node scripts/remove-duplicates.js + - run: node scripts/update-number-of-domains.js - run: node scripts/generate-noip.js - run: node scripts/generate-dnsmasq.js - name: Commit & Push diff --git a/scripts/update-number-of-domains.js b/scripts/update-number-of-domains.js new file mode 100644 index 0000000..5f50f79 --- /dev/null +++ b/scripts/update-number-of-domains.js @@ -0,0 +1,20 @@ +const fs = require("fs").promises; +const path = require("path"); + +(async () => { + const files = (await fs.readdir(path.join(__dirname, ".."))).filter((file) => file.endsWith(".txt")); // Array of strings, each representing a single file that ends in `.txt` + + await Promise.all(files.map(async (file) => { // For each file + const existingDomains = new Set(); + + const fileContents = await fs.readFile(path.join(__dirname, "..", file), "utf8"); // Get file contents as a string + + fileContents.split("\n").forEach((line) => { + if (line.startsWith("0.0.0.0 ")) { + existingDomains.add(line.replace("0.0.0.0 ", "")); + } + }); + + await fs.writeFile(path.join(__dirname, "..", file), fileContents.replace(/^# Total number of network filters: ?(\d*)$/gmu, `# Total number of network filters: ${existingDomains.size}`), "utf8"); + })); +})();