forked from blocklistproject/Lists
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request blocklistproject#348 from fishcharlie/update-numbe…
…r-of-domains Adding script to automate updating number of domains in list
- Loading branch information
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
})); | ||
})(); |