-
Notifications
You must be signed in to change notification settings - Fork 1
/
INC500.js
56 lines (47 loc) · 1.33 KB
/
INC500.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Created by: RemcoE33
https://github.com/RemcoE33/apps-script-codebase
Change the two global variables to your needs.
*/
//Global:
const year = 2021;
const sheetname = 'Inc5000';
function onOpen(e){
SpreadsheetApp.getUi().createMenu('INC')
.addItem('Refesh', 'INC')
.addToUi();
}
function INC(){
console.time('Timer');
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName(sheetname);
//Change year if needed.
const url = `https://api.inc.com/rest/i5list/${year}`
const res = UrlFetchApp.fetch(url);
const data = JSON.parse(res.getContentText());
const output = [];
data.companies.map((comp, index) => {
const object = {
Rank: comp.rank,
Company: comp.company,
Industy: comp.industry,
Founded: comp.founded,
Website: comp.website,
'Years on list': comp.yrs_on_list,
Growth: comp.growth,
Revenue: comp.raw_revenue,
'Previous workers': comp.previous_workers,
Workers: comp.workers,
Metro: comp.metrocode,
State: comp.state_l,
Zipcode: comp.zipcode,
};
if (index == 0){
output.push(Object.keys(object));
}
output.push(Object.values(object));
})
sheet.getDataRange().clearContent();
sheet.getRange(1,1,output.length, output[0].length).setValues(output);
console.timeEnd('Timer');
}