-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateCardData.js
74 lines (59 loc) · 1.89 KB
/
updateCardData.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
const fs = require('fs');
const mtgjsonP = require('mtgjson-promise');
const update = async function() {
let historic = JSON.parse(fs.readFileSync(`./json/historic.json`));
const {data, etag} = await mtgjsonP({extra: true});
let currCard;
let cardData = {};
let cardsToIgnore = [
'Island',
'Plains',
'Swamp',
'Forest',
'Mountain',
'Wastes'
];
for(set in data) {
if (data.hasOwnProperty(set)) {
for (card in data[set].cards) {
if(data[set].cards.hasOwnProperty(card)) {
currCard = data[set].cards[card];
if (currCard.legalities && cardsToIgnore.indexOf(currCard.name) === -1) {
if (!cardData.hasOwnProperty(currCard.name)) {
let legalities = {};
for (var i=0; i<currCard.legalities.length; i++) {
legalities[currCard.legalities[i].format.toLowerCase()] = currCard.legalities[i].legality.toLowerCase();
}
cardData[currCard.name] = {
legalities,
name: currCard.name,
sets: currCard.printings,
colorIdentity: currCard.colorIdentity
}
}
}
}
}
}
}
for (card in cardData) {
if (cardData.hasOwnProperty(card) && cardsToIgnore.indexOf(card) === -1) {
cardData[card]['standards'] = [];
for (standard in historic) {
if (historic.hasOwnProperty(standard)) {
if (standard !== 'banlist' && standard !== 'sets') {
for (var i=0; i<cardData[card].sets.length; i++) {
if (historic[standard].indexOf(cardData[card].sets[i]) !== -1) {
cardData[card]['standards'].push(standard)
}
}
}
}
}
}
}
fs.writeFileSync('./json/cardData.json', JSON.stringify(cardData, undefined, 2));
}
module.exports = {
update
}