Created
June 18, 2017 20:20
-
-
Save cfjedimaster/2582737a213abb54e7b3faee74bc3a07 to your computer and use it in GitHub Desktop.
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 main(args) { | |
return new Promise( (resolve, reject) => { | |
console.log('current max is '+totalChars); | |
var options = { | |
uri: 'https://www.comicvine.com/api/characters', | |
qs: { | |
api_key: key, | |
format:'json', | |
field_list:'aliases,deck,description,first_appeared_in_issue,image,real_name,name,id,publisher,api_detail_url', | |
limit:1, | |
offset:getRandomInt(0,totalChars) | |
}, | |
headers: { | |
'User-Agent': 'Request-Promise' | |
}, | |
json: true | |
}; | |
let character; | |
rp(options) | |
.then(function(json) { | |
//update totalChars | |
totalChars = json.number_of_total_results; | |
//look up details now | |
character = json.results[0]; | |
return rp({ | |
uri:character.api_detail_url, | |
qs:{ | |
api_key:key, | |
format:'json', | |
field_list:'birth,character_enemies,character_friends,creators,powers,teams' | |
}, | |
headers: { | |
'User-Agent': 'Request-Promise' | |
}, | |
json: true | |
}); | |
}) | |
.then(function(json) { | |
console.log('in second then'); | |
character.detail = json.results; | |
resolve({character:character}); | |
}) | |
.catch(function(err) { | |
console.log('error in rp'); | |
reject({error:err}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment