Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function main(args) {
return new Promise( async (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;
// you can wrap the next line in a try/catch if you want to catch network call errors, put reject() in your catch
let json = await rp(options);
//update totalChars
totalChars = json.number_of_total_results;
//look up details now
character = json.results[0];
// again, wrap in try/catch, put reject() in your catch
let secondJson = await 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
});
console.log('second result received');
character.detail = secondJson.results;
resolve({
character: character
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.