Advertisement
Guest User

Untitled

a guest
Apr 18th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. function getData(title) {
  2. return new Promise(function(resolve, reject){
  3. request(`http://www.omdbapi.com/?${title}&apikey=bb5f0ed2`, function(err, res, body){
  4. if (err) {
  5. reject(err);
  6. }
  7. resolve(body);
  8. });
  9. });
  10. }
  11.  
  12. async function showDataWithAsync(title){
  13. let data = await getData(title);
  14.  
  15. let plotIds = JSON.parse(data).Episodes.reduce((array, item) => {
  16. array.push(item.imdbID);
  17. return array;
  18. }, []);
  19.  
  20. //console.log(await getData(`i=${plotIds[0]}`));
  21. let plots = [];
  22. for (let i = 0; i < plotIds.length; i++) {
  23. let thisEpisode = JSON.parse(await getData(`i=${plotIds[i]}`));
  24. plots.push(`Episode: ${thisEpisode.Episode}, Plot: ${thisEpisode.Plot}`);
  25. }
  26. console.log(plots);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement