Skip to content

Instantly share code, notes, and snippets.

@iotashan
Forked from cfjedimaster/partial_snippet.js
Last active June 18, 2017 20:33
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 iotashan/e0f46cb1d8ff84f444ef169ee034fabc to your computer and use it in GitHub Desktop.
Save iotashan/e0f46cb1d8ff84f444ef169ee034fabc to your computer and use it in GitHub Desktop.
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