diff options
Diffstat (limited to 'update/ponies/parse.js')
-rwxr-xr-x | update/ponies/parse.js | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/update/ponies/parse.js b/update/ponies/parse.js index 71ce007..c4cc1d4 100755 --- a/update/ponies/parse.js +++ b/update/ponies/parse.js @@ -25,10 +25,11 @@ const fs = require('fs');
const axios = require('axios');
+const colorlib = require('../../modules/colorlib');
console.log("Parsing infobox data...");
-let ponies = {};
+global.ponies = {};
(async () => {
for (let title in JSON.parse(fs.readFileSync("./data/boxes.json").toString())) {
@@ -40,6 +41,11 @@ let ponies = {}; extract_fr: "",
generation: -1,
color: "000000",
+ search: {
+ mane: [],
+ coat: [],
+ eyes: []
+ },
image: "https://example.com",
kind: "Pony",
sex: "Unknown",
@@ -62,14 +68,54 @@ let ponies = {}; }
if (typeof box.kind !== "undefined") {
- kp = box.kind.replace(/<!--[\s\S]*?-->/g, "").replace(/[^a-zA-Z0-9-_ ]/gm, "").split(" ")[0];
- data.kind = kp.substring(kp.replace(/([A-Z])([a-z0-9]*)$/g, "").length);
+ box.kind = box.kind.replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "\n");
+
+ if (box.kind.includes("\n")) {
+ data.kind = box.kind.replace(/[\[\]]/gm, "").replace(/<(.*)>/gm, "").replace(/([a-zA-Z0-9 \-_,.'"]*)_([a-zA-Z0-9 \-_,.'"]*)/gm, "$2").replace(/^(.*)\|(.*)$/gm, "$2");
+ } else {
+ kp = box.kind.replace(/<!--[\s\S]*?-->/g, "").replace(/[^a-zA-Z0-9-_ ]/gm, "").split(" ")[0];
+ data.kind = kp.substring(kp.replace(/([A-Z])([a-z0-9]*)$/g, "").length);
+ }
+ }
+
+ if (typeof box.sex !== "undefined") {
+ box.sex = box.sex.replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "\n");
+
+ if (box.sex.includes("\n") || box.sex.includes("&")) {
+ data.sex = box.sex.replace(/<!--[\s\S]*?-->/g, "").trim();
+ } else {
+ data.sex = box.sex.replace(/<!--[\s\S]*?-->/g, "").trim().startsWith("F") ? "F" : "M";
+ }
}
- if (typeof box.sex !== "undefined") data.sex = box.sex.replace(/<!--[\s\S]*?-->/g, "").trim().startsWith("F") ? "F" : "M";
if (typeof box._extract !== "undefined") {
data.extract = box._extract;
}
- if (typeof box.coat !== "undefined") data.color = box.coat.replace(/<!--[\s\S]*?-->/g, "").trim().replace(/\[([a-z.\/ \nA-Z0-9:]*)\/(.{6})\/ (.*)\]/gm, "$2").replace(/{{perbang\|([0-9A-Fa-f].{5})(.*)/g, "$1");
+ if (typeof box.coat !== "undefined") data.color = box.coat.trim().replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "|").split("|").map((i) => { return i.replace(/<!--[\s\S]*?-->/g, "").trim().replace(/\[([a-z.\/ \nA-Z0-9:]*)\/(.{6})\/ (.*)\]/gm, "$2").replace(/{{perbang\|([0-9A-Fa-f].{5})(.*)/g, "$1").replace(/\[(.*)\/(.*)\/ (.*)\]/g, "$2"); })[0];
+
+ try {
+ if (typeof box.coat !== "undefined") data.search.coat = box.coat.trim().replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "|").split("|").map((i) => {
+ try {
+ return colorlib("#" + i.replace(/<!--[\s\S]*?-->/g, "").trim().replace(/\[([a-z.\/ \nA-Z0-9:]*)\/(.{6})\/ (.*)\]/gm, "$2").replace(/{{perbang\|([0-9A-Fa-f].{5})(.*)/g, "$1").replace(/\[(.*)\/(.*)\/ (.*)\]/g, "$2"));
+ } catch (e) {}
+ }).filter(i => typeof i !== "number");
+ } catch (e) {}
+
+ try {
+ if (typeof box.eyes !== "undefined") data.search.eyes = box.eyes.trim().replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "|").split("|").map((i) => {
+ try {
+ return colorlib("#" + i.replace(/<!--[\s\S]*?-->/g, "").trim().replace(/\[([a-z.\/ \nA-Z0-9:]*)\/(.{6})\/ (.*)\]/gm, "$2").replace(/{{perbang\|([0-9A-Fa-f].{5})(.*)/g, "$1").replace(/\[(.*)\/(.*)\/ (.*)\]/g, "$2"));
+ } catch (e) {}
+ }).filter(i => typeof i !== "number");
+ } catch (e) {}
+
+ try {
+ if (typeof box.mane !== "undefined") data.search.mane = box.mane.trim().replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "|").split("|").map((i) => {
+ try {
+ return colorlib("#" + i.replace(/<!--[\s\S]*?-->/g, "").trim().replace(/\[([a-z.\/ \nA-Z0-9:]*)\/(.{6})\/ (.*)\]/gm, "$2").replace(/{{perbang\|([0-9A-Fa-f].{5})(.*)/g, "$1").replace(/\[(.*)\/(.*)\/ (.*)\]/g, "$2"));
+ } catch (e) {}
+ }).filter(i => typeof i !== "number");
+ } catch (e) {}
+
try {
if (typeof box.main !== "undefined") data.image = (await axios.head("https://mlp.fandom.com/Special:FilePath/" + encodeURI(box.main.replace(/<!--[\s\S]*?-->/g, "").trim()).replaceAll("?", "%3F").replaceAll("&", "%26"))).request.res.responseUrl;
} catch (e) {
@@ -130,11 +176,11 @@ let ponies = {}; box.residence/*.replace(/\[\[(.*)_(.*)\]\]|\[\[(.*)\|(.*)\]\]|\[\[(.*)\]\]/gm, "$2$4$5")*/.replace(/<!--[\s\S]*?-->/g, "").trim().replace(/\|/gm, "_").replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "|").replace(/( \|| \| | \| )/gm, "|").split("|").forEach((e) => {
residences.push(e.trim().replace(/[\[\]]/gm, "").replace(/<(.*)>/gm, "").replace(/([a-zA-Z0-9 \-_,.'"]*)_([a-zA-Z0-9 \-_,.'"]*)/gm, "$2"));
})
- data.residence = residences.replaceAll("Locations#", "");
+ data.residence = residences.map((i) => { return i.replaceAll("Locations#", "") });
}
if ((typeof box.name2 !== "undefined" || typeof box.name3 !== "undefined" || typeof box.name4 !== "undefined" || typeof box.name5 !== "undefined" || typeof box.coat !== "undefined" || typeof box.occupation !== "undefined" || typeof box.residence !== "undefined") && typeof box.sex !== "undefined") ponies[title] = data;
- }
-})()
-fs.writeFileSync("./data/data.json", JSON.stringify(ponies, null, 4));
\ No newline at end of file + fs.writeFileSync("./data/data.json", JSON.stringify(ponies, null, 4));
+ }
+})()
\ No newline at end of file |