Advertisement
RemcoE33

INC 500

Sep 11th, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onOpen(e){
  2.   SpreadsheetApp.getUi().createMenu('INC')
  3.     .addItem('Refesh', 'INC')
  4.     .addToUi();
  5. }
  6.  
  7. function INC(){
  8.   console.time('Timer');
  9.   const ss = SpreadsheetApp.getActiveSpreadsheet();
  10.   const sheet = ss.getSheetByName('Data');
  11.   const url = 'https://api.inc.com/rest/i5list/2021'
  12.   const res = UrlFetchApp.fetch(url);
  13.   const data = JSON.parse(res.getContentText());
  14.   const output = [];
  15.  
  16.   data.companies.map((comp, index) => {
  17.     const object = {
  18.       Rank: comp.rank,
  19.       Company: comp.company,
  20.       Industy: comp.industry,
  21.       Founded: comp.founded,
  22.       Website: comp.website,
  23.       'Years on list': comp.yrs_on_list,
  24.       Growth: comp.growth,
  25.       Revenue: comp.raw_revenue,
  26.       'Previous workers': comp.previous_workers,
  27.       Workers: comp.workers,
  28.       Metro: comp.metrocode,
  29.       State: comp.state_l,
  30.       Zipcode: comp.zipcode,
  31.     };
  32.  
  33.     if (index == 0){
  34.       output.push(Object.keys(object));
  35.     }
  36.  
  37.     output.push(Object.values(object));
  38.   })
  39.  
  40.   sheet.getDataRange().clearContent();
  41.   sheet.getRange(1,1,output.length, output[0].length).setValues(output);
  42.   console.timeEnd('Timer');
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement