Advertisement
Namokonov

wb_parse

Apr 19th, 2024
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onOpen(){
  2.   SpreadsheetApp.getUi()
  3.   .createMenu("🐱")
  4.   .addItem("запустить!", "myFunction")
  5.   .addToUi();
  6. }
  7.  
  8. function myFunction() {
  9.   const ss = SpreadsheetApp.getActive();
  10.   const sh = ss.getSheetByName("Лист1");
  11.   const nmIds = sh.getDataRange().getValues().slice(1);
  12.   const data = nmIds.map(row => {
  13.     const nmId = row[0];
  14.     const url = getJsonUrl(nmId);
  15.     const r = JSON.parse(UrlFetchApp.fetch(url));
  16.  
  17.     row = [
  18.       url, r.imt_name, r.subj_name, r.subj_root_name, r.vendor_code, r.season, r.description,
  19.       r?.options.map(f => f.name + ": " + f.value).join('\n'),
  20.       r?.grouped_options.map(ff => ff.options.map(fff => ff.group_name + ", " + fff.name + ": " + fff.value).join('\n')).join('\n')
  21.     ];
  22.  
  23.     return row;
  24.   });
  25.  
  26.   sh.getRange("B2:" + data.length).clearContent();
  27.   sh.getRange(2, 2, data.length, data[0].length).setValues(data);
  28. };
  29.  
  30. function getJsonUrl(nmid) {
  31.   const basket = {
  32.     143: '01',
  33.     287: '02',
  34.     431: '03',
  35.     719: '04',
  36.     1007: '05',
  37.     1061: '06',
  38.     1115: '07',
  39.     1169: '08',
  40.     1313: '09',
  41.     1601: '10',
  42.     1655: '11',
  43.     1919: '12',
  44.     2045: '13',
  45.     99999: '14'
  46.   }
  47.   return `https://basket-${basket[Object.keys(basket)
  48.     .filter(v => Math.floor(nmid / 100000) <= v)[0]]}.wb.ru/vol${Math.floor(nmid / 100000)}/part${Math.floor(nmid / 1000)}/${nmid}/info/ru/card.json`
  49. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement