diff options
author | Minteck <contact@minteck.org> | 2022-01-06 22:20:22 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-01-06 22:20:22 +0100 |
commit | e41f05b77fe8d757d8acd6a638d7f2b28155e4e3 (patch) | |
tree | e2fe749ed5e05760ab0877d6b7b9c7bbdca1dcf3 /update/parse.js | |
download | ponyfind-e41f05b77fe8d757d8acd6a638d7f2b28155e4e3.tar.gz ponyfind-e41f05b77fe8d757d8acd6a638d7f2b28155e4e3.tar.bz2 ponyfind-e41f05b77fe8d757d8acd6a638d7f2b28155e4e3.zip |
Initial commit
Diffstat (limited to 'update/parse.js')
-rw-r--r-- | update/parse.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/update/parse.js b/update/parse.js new file mode 100644 index 0000000..570c3fa --- /dev/null +++ b/update/parse.js @@ -0,0 +1,68 @@ +const fs = require('fs'); + +console.log("Parsing infobox data..."); + +let ponies = {}; + +(async () => { + for (let title in JSON.parse(fs.readFileSync("./data/boxes.json").toString())) { + let box = JSON.parse(fs.readFileSync("./data/boxes.json").toString())[title]; + let data = { + names: [title], + color: "000000", + image: "https://example.com", + kind: "Pony", + sex: "Unknown", + occupation: ["Unknown"], + residence: ["Unknown"], + mark: "https://example.com" + } + + if (typeof box.name2 !== "undefined") data.names.push(box.name2); + if (typeof box.name3 !== "undefined") data.names.push(box.name3); + if (typeof box.name4 !== "undefined") data.names.push(box.name4); + if (typeof box.name5 !== "undefined") data.names.push(box.name5); + + if (typeof box.nicknames !== "undefined") { + box.nicknames.split(",").filter(e => !e.match(/[^a-zA-Z0-9-_ ]/gm)).forEach((e, i) => { + data.names.push(e.trim()); + }); + } + + if (typeof box.kind !== "undefined") { + kp = box.kind.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.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["cutie mark"] !== "undefined") { + try { + data.markimg = box["cutie mark"].split("[[File:")[1].split("|")[0]; + } catch (e) { + data.markimg = box["cutie mark"].split("[[File:")[0].split("|")[0]; + } + data.mark = "https://mlp.fandom.com/Special:Redirect/file/" + encodeURI(data.markimg) + "?width=128"; + } + + 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, "")); + }) + 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, "")); + }) + data.residence = residences; + } + + ponies[title] = data; + } +})() + +fs.writeFileSync("./data/data.json", JSON.stringify(ponies, null, 4));
\ No newline at end of file |