Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getData(title) {
- return new Promise(function(resolve, reject){
- request(`http://www.omdbapi.com/?${title}&apikey=bb5f0ed2`, function(err, res, body){
- if (err) {
- reject(err);
- }
- resolve(body);
- });
- });
- }
- async function showDataWithAsync(title){
- let data = await getData(title);
- let plotIds = JSON.parse(data).Episodes.reduce((array, item) => {
- array.push(item.imdbID);
- return array;
- }, []);
- //console.log(await getData(`i=${plotIds[0]}`));
- let plots = [];
- for (let i = 0; i < plotIds.length; i++) {
- let thisEpisode = JSON.parse(await getData(`i=${plotIds[i]}`));
- plots.push(`Episode: ${thisEpisode.Episode}, Plot: ${thisEpisode.Plot}`);
- }
- console.log(plots);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement