-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
73 lines (67 loc) · 1.98 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var axios = require("axios");
const express = require("express");
var cors = require("cors");
const app = express();
const PORT = process.env.PORT || 5000;
const bodyParser = require("body-parser");
const pages = [];
async function getProjectPages(cmcontinue) {
if (cmcontinue) {
return await axios.get(
`https://www.appropedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category%3AProjects&format=json&cmlimit=500&cmcontinue=${cmcontinue}`
);
} else {
return await axios.get(
`https://www.appropedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category%3AProjects&format=json&cmlimit=500`
);
}
}
async function getProjectTitlesWrapper(cmcontinue) {
console.log("🔍 Getting project titles...");
return new Promise(async function getProjectTitles(
resolve,
reject,
cmcontinue
) {
const { data: resp } = await getProjectPages(cmcontinue);
for (page of resp.query.categorymembers) {
pages.push(page);
}
if (resp.continue) {
getProjectTitles(resolve, reject, resp.continue.cmcontinue);
} else {
resolve();
}
});
}
async function getValidity(title) {
console.log(title);
const { data: resp } = await axios.get(
`https://oshwa-appro-jackpeplinski.vercel.app/checkValidity/${encodeURIComponent(title)}`
);
if (Array.isArray(resp)) {
return { validStatus: false, numberMissing: resp.length };
} else {
return { validStatus: true };
}
}
async function start() {
console.log("🏃🏽 Starting run...");
await getProjectTitlesWrapper();
for (page of pages) {
var validCount = 0,
invalidCount = 0,
numberMissing = 0;
const validity = await getValidity(page.title);
if (validity.validStatus) {
validCount++;
} else {
invalidCount++;
numberMissing += numberMissing;
}
}
console.log("Invalid count", invalidCount);
console.log("Valid count", validCount);
console.log("Number missing", numberMissing / invalidCount);
}
start();