aboutsummaryrefslogtreecommitdiff
path: root/update/infobox.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-01-06 22:20:22 +0100
committerMinteck <contact@minteck.org>2022-01-06 22:20:22 +0100
commite41f05b77fe8d757d8acd6a638d7f2b28155e4e3 (patch)
treee2fe749ed5e05760ab0877d6b7b9c7bbdca1dcf3 /update/infobox.js
downloadponyfind-e41f05b77fe8d757d8acd6a638d7f2b28155e4e3.tar.gz
ponyfind-e41f05b77fe8d757d8acd6a638d7f2b28155e4e3.tar.bz2
ponyfind-e41f05b77fe8d757d8acd6a638d7f2b28155e4e3.zip
Initial commit
Diffstat (limited to 'update/infobox.js')
-rw-r--r--update/infobox.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/update/infobox.js b/update/infobox.js
new file mode 100644
index 0000000..26a989d
--- /dev/null
+++ b/update/infobox.js
@@ -0,0 +1,30 @@
+const fs = require('fs');
+const axios = require("axios");
+const WikiTextParser = require('parse-wikitext');
+const parser = new WikiTextParser("mlp.fandom.com");
+
+console.log("Gathering infobox for each page...");
+
+(async () => {
+ let infoboxes = {};
+ for (let page of JSON.parse(fs.readFileSync("./data/pages.json").toString())) {
+ console.log("Gathering infobox for '" + page.name + "'...");
+ try {
+ let data = (await axios.get("https://mlp.fandom.com/api.php?action=query&prop=revisions&titles=" + page.name + "&rvslots=*&rvprop=content&formatversion=2&format=json")).data;
+ if (data.query.pages.length > 0) {
+ console.log("Results found, adding name to database")
+ sections = parser.pageToSectionObject(data.query.pages[0].revisions[0].slots.main.content);
+ box = parser.parseInfoBox(sections["content"]);
+ if (box.template === "Infobox character") {
+ infoboxes[page.name] = parser.parseInfoBox(sections["content"]).values;
+ }
+ } else {
+ console.log("No results found, ignoring name");
+ }
+ } catch (e) {
+ console.error(e);
+ }
+ }
+
+ fs.writeFileSync("./data/boxes.json", JSON.stringify(infoboxes, null, 4))
+})() \ No newline at end of file