Last active
July 9, 2024 13:31
-
-
Save ChlodAlejandro/f1c4a48f6a7b9d2d571c6e1bc6dadf24 to your computer and use it in GitHub Desktop.
Wikimedia project count.
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
const includeClosed = false; | |
const includeFishbowl = false; | |
const includePrivate = false; | |
const includeNonglobal = false; | |
fetch("https://meta.wikimedia.org/w/api.php?action=sitematrix&format=json&formatversion=2") | |
.then(r => r.json()) | |
.then(({ sitematrix }) => { | |
let count = 0; | |
if (includeClosed && includeFishbowl && includePrivate && includeNonglobal) | |
return sitematrix.count; | |
for (const lang of Object.values(sitematrix)) { | |
if (lang.site) { | |
count += lang.site | |
.filter(v => includeClosed || !v.closed) | |
.filter(v => includeFishbowl || !v.fishbowl) | |
.filter(v => includePrivate || !v.private) | |
.filter(v => includeNonglobal || !v.nonglobal) | |
.length; | |
} else if (Array.isArray(lang)) { | |
// specials | |
count += lang | |
.filter(v => includeClosed || !v.closed) | |
.filter(v => includeFishbowl || !v.fishbowl) | |
.filter(v => includePrivate || !v.private) | |
.filter(v => includeNonglobal || !v.nonglobal) | |
.length; | |
} | |
} | |
return count; | |
}) | |
.then(console.log.bind(null, "Count: ")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment