Skip to content

Instantly share code, notes, and snippets.

@ChlodAlejandro
Last active July 9, 2024 13:31
Show Gist options
  • Save ChlodAlejandro/f1c4a48f6a7b9d2d571c6e1bc6dadf24 to your computer and use it in GitHub Desktop.
Save ChlodAlejandro/f1c4a48f6a7b9d2d571c6e1bc6dadf24 to your computer and use it in GitHub Desktop.
Wikimedia project count.
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