This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetPerks.js
78 lines (75 loc) · 2.8 KB
/
getPerks.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const fs = require('fs');
const { JSDOM } = require('jsdom');
const request = require('request');
const download = (url, path, callback) => {
request.head(url, (err, res, body) => {
request(url).pipe(fs.createWriteStream(path))
})
}
(async function () {
if (fs.existsSync("../data/Killers")) return;
// Grab webpage
const dom = await JSDOM.fromURL("https://deadbydaylight.fandom.com/wiki/Killer_Perks");
const { document } = dom.window;
// First element is apparently thead (jsdom is wack)
// Grab all rows in table
perks = [...document.querySelector("tbody").children].slice(1)
.map((x) => {
// Remap each row into object
return {
filename: x.querySelectorAll("a")[0].href.replace(/\/revision\/latest.+/, ""),
name: x.querySelectorAll("a")[1].title.replaceAll(":", "").normalize("NFD").replace(/[\u0300-\u036f]/g, ""),
// Description is URI encoded for simplicity
killer: x.children[3].querySelectorAll("a")[0]?.textContent?.normalize("NFD")?.replace(/[\u0300-\u036f]/g, "")
}
});
groupedPerks = perks.reduce((acc, value) => {
if (!acc[value.killer]) {
acc[value.killer] = [];
}
acc[value.killer].push(value);
return acc;
}, {});
fs.mkdirSync("../data/Killers");
for (let killer in groupedPerks) {
killerName = killer == 'undefined' ? 'CommonKiller' : killer;
fs.mkdirSync(`../data/Killers/${killerName}`);
for (perk of groupedPerks[killer]) {
download(perk.filename, `../data/Killers/${killerName}/${perk.name}.png`);
}
}
}());
(async function () {
if (fs.existsSync("../data/Survivors")) return;
// Grab webpage
const dom = await JSDOM.fromURL("https://deadbydaylight.fandom.com/wiki/Survivor_Perks");
const { document } = dom.window;
// First element is apparently thead (jsdom is wack)
// Grab all rows in table
perks = [...document.querySelector("tbody").children].slice(1)
.map((x) => {
// Remap each row into object
return {
filename: x.querySelectorAll("a")[0].href.replace(/\/revision\/latest.+/, ""),
name: x.querySelectorAll("a")[0].title.replaceAll(":", "").normalize("NFD").replace(/[\u0300-\u036f]/g, ""),
// Description is URI encoded for simplicity
survivor: x.children[3].querySelector("a")?.title?.replaceAll("\"", "'")?.normalize("NFD")?.replace(/[\u0300-\u036f]/g, "")
}
});
groupedPerks = perks.reduce((acc, value) => {
if (value.survivor == undefined) value.survivor = "CommonSurvivor";
if (!acc[value.survivor]) {
acc[value.survivor] = [];
}
acc[value.survivor].push(value);
return acc;
}, {});
fs.mkdirSync("../data/Survivors");
for (survivor in groupedPerks) {
survivorName = survivor == 'undefined' ? 'CommonSurvivor' : survivor;
fs.mkdirSync(`../data/Survivors/${survivorName}`);
for (perk of groupedPerks[survivor]) {
download(perk.filename, `../data/Survivors/${survivorName}/${perk.name}.png`);
}
}
}());