blob: 8449ca58afc494fdb4667e4253f930a9dad801d8 (
plain)
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
|
const fs = require('fs');
const axios = require('axios');
if (fs.existsSync("./data")) fs.rmSync("./data", { recursive: true });
fs.mkdirSync("./data");
(async () => {
console.log("Gathering pages list...");
let pages = [];
for (let page of JSON.parse(fs.readFileSync("list.json").toString())) {
console.log("Searching for '" + page + "'...");
try {
let data = (await axios.get("https://mlp.fandom.com/api.php?action=query&list=search&srsearch=" + encodeURI(page) + "&srlimit=1&srenablerewrites=true&format=json")).data;
if (data.query.search.length > 0) {
console.log("Results found, adding name to database")
pages.push({
query: page,
name: data.query.search[0].title,
mwid: data.query.search[0].pageid,
words: data.query.search[0].wordcount,
})
} else {
console.log("No results found, ignoring name");
}
} catch (e) {
console.error(e);
}
}
fs.writeFileSync("./data/pages.json", JSON.stringify(pages, null, 4))
})()
|