always_lucky

comments

Mar 13th, 2021 (edited)
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const BATCH_SIZE = 100;
  2. async function getComments(requestData, searchLimit) {
  3.     const comments = [];
  4.     // copy request data in order to doesn't modify original request data if it doesn't contain nested objects
  5.     const requestData = { ... requestData };
  6.     let isDone = false;
  7.  
  8.     do {
  9.         const commentsResponse = await gapi.client.youtube.commentThreads.list(requestData);
  10.         const retrievedComments = response.result.items;
  11.         if(searchLimit <= BATCH_SIZE) {
  12.             comments.push(retrievedComments.slice(0, searchLimit));
  13.             isDone = true;
  14.         } else {
  15.             comments.push(retrievedComments);
  16.             if(response.result.nextPageToken != undefined) {
  17.                 requestData.pageToken = response.result.nextPageToken;
  18.             } else {
  19.                 isDone = true;
  20.             }
  21.         }
  22.         searchLimit -= BATCH_SIZE;
  23.     } while(isDone)
  24.    
  25.     return comments;
  26. }
  27.  
  28. ### Usage
  29.  
  30. async function run() {
  31.     // я не представляю что там у тебя за обработка ошибок в SearchExceptionLog, так что тут думай сам
  32.     const comments = await getComments(yourRequestData, 8841)
  33.         .catch((err) => {
  34.             SearchExceptionLog(err);
  35.             process.exit(1);
  36.         })
  37.  
  38.     // я не предсталвляю что делает эта функция и асинхронная ли она, так что тут думай сам
  39.     const search = SearchInList(comments);
  40. }
  41.  
Add Comment
Please, Sign In to add comment