Skip to content

Instantly share code, notes, and snippets.

@Restuta
Created July 20, 2015 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Restuta/9eea61605c01c81dc991 to your computer and use it in GitHub Desktop.
Save Restuta/9eea61605c01c81dc991 to your computer and use it in GitHub Desktop.
Find MARVEL characters without images
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