Last active
January 14, 2016 21:04
-
-
Save lsmoura/7126297c07afe813b0cf to your computer and use it in GitHub Desktop.
Generate pak90.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
path = require('path'), | |
tiptoe = require('tiptoe'), | |
mtgdb = require('mtgdb'); | |
/* | |
npm install tiptoe | |
npm install https://github.com/mtgjson/mtgdb.git | |
*/ | |
function clone(obj) { | |
return(JSON.parse(JSON.stringify(obj))); | |
} | |
function processSet(setData, allCards, cb) { | |
var i, l = setData.cards.length; | |
for (i = 0; i < l; i++) { | |
var currentCard = setData.cards[i]; | |
if (currentCard.multiverseid) { | |
if (!allCards.hasOwnProperty(currentCard.name)) { | |
allCards[currentCard.name] = clone(currentCard); | |
delete allCards[currentCard.name].multiverseid; | |
delete allCards[currentCard.name].originalText; | |
delete allCards[currentCard.name].originalType; | |
delete allCards[currentCard.name].mciNumber; | |
delete allCards[currentCard.name].reserved; | |
allCards[currentCard.name].multiverseids = []; | |
} | |
allCards[currentCard.name].multiverseids.push({ | |
'setCode': setData.code, | |
'multiverseid': currentCard.multiverseid | |
}); | |
} | |
} | |
if (cb) | |
cb(); | |
} | |
tiptoe( | |
function grabVersion() { | |
mtgdb.currentVersion(this); | |
}, | |
function checkVersion(version) { | |
console.log("Current version: '%s'", version); | |
if (version === "") { | |
console.log("Downloading..."); | |
mtgdb.grabServerContents(this); | |
} | |
else | |
mtgdb.allsets(this); | |
}, | |
function process(allSets) { | |
console.log("Processing sets..."); | |
this.allCards = {}; | |
var keys = Object.keys(allSets); | |
var i, l = keys.length; | |
for (i = 0; i < l; i++) { | |
var currentSet = allSets[keys[i]]; | |
processSet(currentSet, this.allCards); | |
} | |
this(null, this.allCards); | |
}, | |
function saveData(allCards) { | |
fs.writeFile(path.join(__dirname, 'pak90.json'), JSON.stringify(allCards, null, ' '), 'utf8', this); | |
}, | |
function finish(err) { | |
if (err) { | |
console.error(err); | |
throw(err); | |
} | |
console.log('done'); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment