Skip to content

Commit

Permalink
Merge pull request blocklistproject#348 from fishcharlie/update-numbe…
Browse files Browse the repository at this point in the history
…r-of-domains

Adding script to automate updating number of domains in list
  • Loading branch information
blocklistproject authored Jun 28, 2021
2 parents ffff13d + 34fdcee commit b0e3a0c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run-automations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions scripts/update-number-of-domains.js
Original file line number Diff line number Diff line change
@@ -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");
}));
})();

0 comments on commit b0e3a0c

Please sign in to comment.