aboutsummaryrefslogtreecommitdiff
path: root/update/parse.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-01-08 21:47:45 +0100
committerMinteck <contact@minteck.org>2022-01-08 21:47:45 +0100
commitbe6c790e43be36cfa6669110c7064a67ad3c4623 (patch)
tree3e81dd5a8caaf3f9c9db6b21f858167f01983119 /update/parse.js
parentac2dea4a23ca72001e41c1dbf66ff1a0d01e217c (diff)
downloadponyfind-be6c790e43be36cfa6669110c7064a67ad3c4623.tar.gz
ponyfind-be6c790e43be36cfa6669110c7064a67ad3c4623.tar.bz2
ponyfind-be6c790e43be36cfa6669110c7064a67ad3c4623.zip
Update
Diffstat (limited to 'update/parse.js')
-rw-r--r--update/parse.js25
1 files changed, 19 insertions, 6 deletions
diff --git a/update/parse.js b/update/parse.js
index 570c3fa..6f4ee3a 100644
--- a/update/parse.js
+++ b/update/parse.js
@@ -1,4 +1,5 @@
const fs = require('fs');
+const axios = require('axios');
console.log("Parsing infobox data...");
@@ -6,9 +7,12 @@ let ponies = {};
(async () => {
for (let title in JSON.parse(fs.readFileSync("./data/boxes.json").toString())) {
+ console.log("Parsing " + title + "...");
let box = JSON.parse(fs.readFileSync("./data/boxes.json").toString())[title];
let data = {
names: [title],
+ extract: "",
+ extract_fr: "",
color: "000000",
image: "https://example.com",
kind: "Pony",
@@ -30,13 +34,22 @@ let ponies = {};
}
if (typeof box.kind !== "undefined") {
- kp = box.kind.replace(/[^a-zA-Z0-9-_ ]/gm, "").split(" ")[0];
+ kp = box.kind.replace(/<!--[\s\S]*?-->/g, "").replace(/[^a-zA-Z0-9-_ ]/gm, "").split(" ")[0];
data.kind = kp.substr(kp.replace(/([A-Z])([a-z0-9]*)$/g, "").length);
}
if (typeof box.sex !== "undefined") data.sex = box.sex.startsWith("F") ? "F" : "M";
+ if (typeof box._extract !== "undefined") {
+ data.extract = box._extract;
+ }
+ if (typeof box._extract_fr !== "undefined") {
+ data.extract_fr = box._extract_fr.replace(/ma petite amitié de poney est la magie/gmi, "My Little Pony Friendship is Magic").replace(/Mon amitié avec mon petit poney est magique/gmi, "My Little Pony Friendship is Magic").replace(/Mon petit Poney/gmi, "My Little Pony").replace(/Mon Petit Poney Une Nouvelle Génération/gmi, "My Little Pony A New Generation").replace(/Mon petit poney : une nouvelle génération/gmi, "My Little Pony: A New Generation").replace(/pegasus/gmi, "pégase").replace(/alicorn[^e]/gmi, "alicorne").replace(/une poney/gmi, "une ponette").replace(/petite génération de poney 5/gmi, "Génération 5");
+ } else {
+ data.extract_fr = data.extract;
+ }
if (typeof box.coat !== "undefined") data.color = box.coat.replace(/\[(.*)\/(.{6})\/ (.*)\]/gm, "$2").replace(/{{perbang\|([0-9A-Fa-f].{5})(.*)/g, "$1");
if (typeof box.main !== "undefined") data.image = "https://mlp.fandom.com/Special:FilePath/" + encodeURI(box.main);
if (typeof box.main1 !== "undefined") data.image = "https://mlp.fandom.com/Special:FilePath/" + encodeURI(box.main1);
+ if (typeof box.image !== "undefined") data.image = "https://mlp.fandom.com/Special:FilePath/" + encodeURI(box.image);
if (typeof box["cutie mark"] !== "undefined") {
try {
data.markimg = box["cutie mark"].split("[[File:")[1].split("|")[0];
@@ -48,20 +61,20 @@ let ponies = {};
if (typeof box.occupation !== "undefined") {
occupations = [];
- box.occupation.replace(/\((.*)\)/gm, "").replace(/\[\[(.*)_(.*)\]\]|\[\[(.*)\|(.*)\]\]|\[\[(.*)\]\]/gm, "$2$4$5").replace(/\|/gm, "_").replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "|").replace(/( \|| \| | \| )/gm, "|").split("|").forEach((e) => {
- occupations.push(e.trim().replace(/[\[\]]/gm, "").replace(/<(.*)>/gm, ""));
+ box.occupation/*.replace(/\[\[(.*)_(.*)\]\]|\[\[(.*)\|(.*)\]\]|\[\[(.*)\]\]/gm, "$2$4$5")*/.replace(/\|/gm, "_").replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "|").replace(/( \|| \| | \| )/gm, "|").split("|").forEach((e) => {
+ occupations.push(e.trim().replace(/[\[\]]/gm, "").replace(/<(.*)>/gm, "").replace(/([a-zA-Z0-9 \-_,.'"]*)_([a-zA-Z0-9 \-_,.'"]*)/gm, "$2"));
})
data.occupation = occupations;
}
if (typeof box.residence !== "undefined") {
residences = [];
- box.residence.replace(/\((.*)\)/gm, "").replace(/\[\[(.*)_(.*)\]\]|\[\[(.*)\|(.*)\]\]|\[\[(.*)\]\]/gm, "$2$4$5").replace(/\|/gm, "_").replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "|").replace(/( \|| \| | \| )/gm, "|").split("|").forEach((e) => {
- residences.push(e.trim().replace(/[\[\]]/gm, "").replace(/<(.*)>/gm, ""));
+ box.residence/*.replace(/\[\[(.*)_(.*)\]\]|\[\[(.*)\|(.*)\]\]|\[\[(.*)\]\]/gm, "$2$4$5")*/.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;
}
- ponies[title] = data;
+ 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") ponies[title] = data;
}
})()