-
-
Save iotashan/e0f46cb1d8ff84f444ef169ee034fabc 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( 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