Created
July 20, 2015 06:26
-
-
Save Restuta/9eea61605c01c81dc991 to your computer and use it in GitHub Desktop.
Find MARVEL characters without images
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
function getRandomBetween(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
var apiKey = 'apikey=ed23113a7ebab2304b0aad655ec41c6a'; | |
var totalCharacters = 1485; | |
var randomOffset = getRandomBetween(1, totalCharacters); | |
//var randomOffset = 1341; | |
var idsOfCharsWithoutImage = []; | |
var imageNotAvailable = 'image_not_available'; | |
var offset = 0; | |
var total = totalCharacters; | |
//var total = 10; | |
var promises = []; | |
for(var i = 0; i < total; i++) { | |
var promise = $.get('http://gateway.marvel.com:80/v1/public/characters?limit=1&offset=' + offset + '&' + apiKey) | |
.then(function(result) { | |
var character = result.data.results[0]; | |
console.log(character.id); | |
if (!character.thumbnail || !character.thumbnail.path || character.thumbnail.path.indexOf(imageNotAvailable) > -1) { | |
idsOfCharsWithoutImage.push(character.id); | |
} | |
}); | |
promises.push(promise); | |
offset = i; | |
} | |
Promise.all(promises).then(function() { | |
console.log('all done'); | |
console.info('chars without image: ' + idsOfCharsWithoutImage.length); | |
console.info(idsOfCharsWithoutImage); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment