Advertisement
Namokonov

main_send_all

Dec 24th, 2021
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function main_send_all() {
  2.   const ss = SpreadsheetApp.openByUrl('url таблицы');
  3.   const sh = ss.getSheetByName('//');
  4.   const now = new Date();
  5.   const hour = now.getHours();
  6.  
  7.   const values = sh.getDataRange().getValues();
  8.   const botToken = values[1][10];
  9.  
  10.   for (var row = 2; row < values.length; row++) {
  11.     const x = values[row];
  12.     const [url, sheetRange, ids, subj, freq, hours, format, last] = [x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7]];
  13.     const [day, hour] = [now.getDay() ? now.getDay() : 7, now.getHours().toString()];
  14.  
  15.     if (x.length > 5
  16.       // && freq.indexOf(day) != -1
  17.       // && hours.toString().split(';').filter(g => g == hour).length
  18.       // && (!last || d2s(last) != d2s(now))
  19.       ){
  20.  
  21.       const ss0 = SpreadsheetApp.openByUrl(x[0]);
  22.       const blob = toPdf(ss0, sheetRange);
  23.  
  24.       let r;
  25.       ids.split(",").forEach(h => {
  26.         if (!format || format == 'JPG') { r = sendPhoto(h, blob, botToken, subj) }
  27.         else if (format == 'PDF') { r = sendDoc(h, blob, botToken, subj) }
  28.       });
  29.  
  30.       sh.getRange(row + 1, 8, 1, 2).setValues([[new Date(), JSON.parse(r).ok == true ? '' : r]]);
  31.     }
  32.     SpreadsheetApp.flush();
  33.   }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement