-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathesi-nameloader.gs
44 lines (38 loc) · 1.19 KB
/
esi-nameloader.gs
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
/*
* Loads names from ESI, using ids
* @param nameids A range where the nameids can be found
* @return the names of the people
* @customfunction
*/
function nameloader(nameIDs) {
if (typeof nameIDs == 'undefined'){
throw 'need name ids';
}
var names = new Array();
var dirtynameids = new Array();
var cleannameids = new Array();
var url="https://esi.evetech.net/latest/universe/names/?datasource=tranquility";
nameIDs.forEach (function (row) {
row.forEach ( function (cell) {
if (typeof(cell) === 'number' ) {
dirtynameids.push(cell);
}
});
});
cleannameids = dirtynameids.filter(function(v,i,a) {
return a.indexOf(v)===i;
});
var parameters = {method : "post", payload : ""};
var o,j,temparray,chunk = 100;
for (o=0,j=cleannameids.length; o < j; o+=chunk) {
temparray = cleannameids.slice(o,o+chunk);
parameters['payload']=JSON.stringify(temparray)
var jsonfeed = UrlFetchApp.fetch(url, parameters).getContentText();
var datafeed=JSON.parse(jsonfeed);
for(var i = 0; i < datafeed.length; i++) {
var namedata=[parseInt(datafeed[i]['id']),datafeed[i]['name']];
names.push(namedata);
}
}
return names;
}