-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgdoc_scripts.js
2300 lines (2122 loc) · 62.2 KB
/
gdoc_scripts.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*-------------------
Developed by: John Purcell
Contact info
- Twitter: @HLIBindustry
- Blog: eve-prosper.blogspot.com
Purpose:
A suite of API/CREST scraping tools for use in Google sheets for EVE Online data
Legal:
API/CREST is property of CCP hf.
Code is distributed free-of-charge, and should not be used for commercial gain
Code is open source, but notification is appreciated on any modifications
Developed as part of the CriusDev project: https://github.com/lockefox/CriusDev
*/
var base_CREST_URL = "https://crest-tq.eveonline.com/";
var test_CREST_URL = "https://api-sisi.testeveonline.com/";
var base_API_URL = "https://api.eveonline.com/char/AssetList.xml.aspx?";
var jobType ={};
var min_wait = 10;
var max_wait = 500;
JobType = {1:"Manufacturing",
3:"Researching Time Efficiency",
4:"Researching Material Efficiency",
5:"Copying",
7:"Reverse Engineering",
8:"Invention"};
var jobType_arr = [];
jobType_arr = ["NOT VALID", "Manufacturing", "NOT VALID", "Researching Time Efficiency", "Researching Material Efficiency", "Copying", "NOT VALID", "Reverse Engineering", "Invention"];
//TODO: verify status values//
var status_arr = [];
status_arr = ["Failed", "Delivered", "Aborted", "GM Aborted", "Inflight Unachored", "Destroyed"];
//// UTILITIES ////
function isInArray(value, array) {
return array.indexOf(value) > -1;
}
function lshift(data_array, shift_count){//shifts an array left. DESTRUCTIVE!
var hold_array = [];
var filler ="";
var data_copy = data_array;//holds data (destructive operation)
for (var rows=0; rows < data_array.length; rows++){
hold_array = data_copy[rows];
for (var cnt=0; cnt < shift_count; cnt++){
var trash = hold_array.shift();
}
data_copy[rows]=hold_array;
}
return data_copy;
}
function zero_array(array_length){
var out_array = []
for (var i=0; i<array_length; i++){
out_array[i]=0
}
return out_array
}
function date_array(days)
{
var daterange = [];
var mydate = new Date();
mydate.setDate(mydate.getDate()-1);//API doesn't give TODAY's data
for (var datestep=0; datestep<days; datestep++)
{
var datestr = "";
var month = mydate.getMonth()+1;
if (month < 10)
{
month = "0"+month;
}
var day = mydate.getDate();
if (day <10)
{
day = "0"+day;
}
datestr = mydate.getFullYear()+"-"+month+"-"+day+"T00:00:00";
daterange[datestep] = datestr;
mydate.setDate(mydate.getDate()-1);
}
return daterange;
}
function getAllianceID(keyID, vCode, systemList)
{
parameters = {
method : "post",
payload :
"keyID=" + encodeURIComponent(keyID) +
"&vCode=" + encodeURIComponent(vCode)
};
Utilities.sleep(1000);
var info = ""
try{//generic query error
Utilities.sleep(1000);
var info = UrlFetchApp.fetch("https://api.eveonline.com/account/APIKeyInfo.xml.aspx?",parameters).getContentText();
}catch (e){
throw e;
}
var infoXML = Xml.parse(info,true);
var KeyOwnerInfo = infoXML.eveapi.result.key.rowset.row.getElements();
var allianceID = Number(KeyOwnerInfo.getAttribute("allianceID").getValue());
return allianceID;
}
function fetchRawAPI(keyID,vCode,API_string,add_args,test_server)
{
if(add_args)
{
var parameters = {
method : "post",
payload :
"keyID=" + encodeURIComponent(keyID) +
"&vCode=" + encodeURIComponent(vCode) +
add_args,
user_agent : "Lockefox @HLIBindustry GDOC scripts",
};
}
else
{
var parameters = {
method : "post",
payload :
"keyID=" + encodeURIComponent(keyID) +
"&vCode=" + encodeURIComponent(vCode),
user_agent : "Lockefox @HLIBindustry GDOC scripts",
};
}
var API_addr = "";
if(test_server) API_addr = "https://api.testeveonline.com/";
else API_addr = "https://api.eveonline.com/";
var info = ""
var ret_arr = []
try{//generic query error
Utilities.sleep(1000);
var info = UrlFetchApp.fetch(API_addr+API_string,parameters).getContentText();
}catch (e){
ret_arr.push(e);
try{
if(add_args)
{
var parameters = {
method : "post",
payload :
"keyID=" + encodeURIComponent(keyID) +
"&vCode=" + encodeURIComponent(vCode) +
add_args,
user_agent : "Lockefox @HLIBindustry GDOC scripts",
muteHttpExceptions : true
};
}
else
{
var parameters = {
method : "post",
payload :
"keyID=" + encodeURIComponent(keyID) +
"&vCode=" + encodeURIComponent(vCode),
user_agent : "Lockefox @HLIBindustry GDOC scripts",
muteHttpExceptions : true
};
}
Utilities.sleep(1000);
info = UrlFetchApp.fetch(API_addr+API_string,parameters).getContentText()
ret_arr.push(info)
}
catch (er){
throw er
}
return ret_arr
}
return info
}
//// FETCH FUNCS ////
function __fetchCrest_market(region_id,item_id)
{
var parameters = {
method : "get",
user_agent : "Lockefox @HLIBindustry GDOC scripts",
}
var sleeptime = min_wait + (max_wait - min_wait)*Math.random();
Utilities.sleep(sleeptime);
var url = base_CREST_URL+"market/"+region_id+"history/?type="+base_CREST_URL+"inventory/types/"+item_id+"/"
var text = UrlFetchApp.fetch(url,parameters);
var json_obj = JSON.parse(text);
return json_obj;
}
function __fetchSystemIndexes(test_server)
{
var base_url="";
if(test_server) base_url = test_CREST_URL;
else base_url = base_CREST_URL;
// if(test_server === undefined) base_url = base_CREST_URL; //allow switching between test/live server (for debug)
// else base_url = test_CREST_URL;
//
var parameters = {
method : "get",
user_agent : "Lockefox @HLIBindustry GDOC scripts",
}
var url = base_url+"industry/systems/";
Utilities.sleep(1000);
var text = UrlFetchApp.fetch(url,parameters);
var json_obj = JSON.parse(text);
return json_obj;
}
function __fetchMarketPrices(test_server)
{
var base_url="";
if(test_server) base_url = test_CREST_URL;
else base_url = base_CREST_URL;
// if(test_server === undefined) base_url = base_CREST_URL; //allow switching between test/live server (for debug)
// else base_url = test_CREST_URL;
//
var parameters = {
method : "get",
user_agent : "Lockefox @HLIBindustry GDOC scripts",
}
var url = base_url+"market/prices/";
Utilities.sleep(1000);
var text = UrlFetchApp.fetch(url,parameters);
var json_obj = JSON.parse(text);
return json_obj;
}
function API_validateKey(keyID, vCode, expected_type, CAK_mask, test_server)
{
//Takes API info and throws errors if bad
var parameters = {
method : "post",
payload :
"keyID=" + encodeURIComponent(keyID) +
"&vCode=" + encodeURIComponent(vCode),
user_agent : "Lockefox @HLIBindustry GDOC scripts",
};
var API_addr = "";
if(test_server) API_addr = "https://api.testeveonline.com/";
else API_addr = "https://api.eveonline.com/";
var info = ""
try{//generic query error
Utilities.sleep(1000);
var info = UrlFetchApp.fetch(API_addr+"account/APIKeyInfo.xml.aspx?",parameters).getContentText();
}catch (e){
throw e;
}
var infoXML = Xml.parse(info,true);
var accessMask = infoXML.eveapi.result.key.getAttribute("accessmask").getValue();
var keytype = infoXML.eveapi.result.key.getAttribute("type").getValue();
if (keytype != expected_type){
if (!(keytype == "Account" && expected_type == "Character"))
throw "Invalid key type:" + keytype + "Expected: " + expected_type;
}
if ((Number(accessMask) & CAK_mask) == 0){
throw "Invalid access mask: " + accessMask + "Expected: " + CAK_mask;
}
//make "EXPIRED" case
}
//// GDOC FUNCS ////
function getPOS(keyID, vCode, header_bool, verbose_bool, test_server)
{
var can_Locations = true;
var can_POSDetails= true;
try{
var can_Locations = true;
API_validateKey(keyID, vCode, "Corporation", 16777216, test_server);
}catch(err){
can_Locations = false;
}
try{
var can_POSDetails= true;
API_validateKey(keyID, vCode, "Corporation", 131072, test_server);
}catch(err){
can_POSDetails = false;
}
try{
API_validateKey(keyID, vCode, "Corporation", 524288, test_server);
}catch(err){
return err;
}
//var allianceID = getAllianceID(keyID, vCode);
parameters = {
method : "post",
payload :
"keyID=" + encodeURIComponent(keyID) +
"&vCode=" + encodeURIComponent(vCode),
user_agent : "Lockefox @HLIBindustry GDOC scripts",
};
Utilities.sleep(1000);
var API_addr = "";
var call_mod = "";
//switch call for test/live server
if(test_server) API_addr = "https://api.testeveonline.com/";
else API_addr = "https://api.eveonline.com/";
var api_query = API_addr+"corp/StarbaseList.xml.aspx?"//keyID="+keyID+"&vCode="+vCode;
var POS_api = UrlFetchApp.fetch(api_query, parameters).getContentText();
var POSXML = Xml.parse(POS_api,true);
var POSList = POSXML.eveapi.result.rowset.getElements("row");
//var standings_owner = POSList[0].getAttribute("standingOwnerID");
var return_array = [];
if(header_bool)
{
var header = []
if (verbose_bool) header.push("itemID");
if (can_Locations) header.push("towerName");
if (verbose_bool) header.push("typeID");
header.push("typeName");
if (verbose_bool) header.push("solarSystemID");
header.push("solarSystemName");
if (verbose_bool) header.push("moonID");
header.push("Location");
header.push("Status");
if (verbose_bool) header.push("stateTimestamp");
if (verbose_bool) header.push("onlineTimestamp");
if (verbose_bool) header.push("standingOwnerID");
if (verbose_bool) header.push("standingOwner");
if (can_POSDetails) header.push("fuelRemaining");
if (can_POSDetails) header.push("chartersRemaining");
if (can_POSDetails) header.push("strontiumRemaining");
if (can_POSDetails) header.push("fuelTimeHours");
if (can_POSDetails) header.push("strontTimeHours");
return_array.push(header);
}
var towerIDs = [];
var towerName_conv = {};
if(can_Locations || can_POSDetails)
{//get a towerID list
for (var towerNum = 0; towerNum < POSList.length; towerNum++)
{
towerIDs.push(POSList[towerNum].getAttribute("itemid").getValue());
}
if(can_Locations && (POSList.length > 0))
towerName_conv = getLocations(keyID, vCode, towerIDs.join(), test_server);
}
for(var towerNum = 0; towerNum < POSList.length; towerNum++)
{
var tower_line = [];
var towerID = POSList[towerNum].getAttribute("itemid").getValue();
var towerName = "";
if(can_Locations)
towerName = towerName_conv[towerID];
var towerTypeID = POSList[towerNum].getAttribute("typeid").getValue();
var solarSystemID = POSList[towerNum].getAttribute("locationid").getValue();
var moonID = POSList[towerNum].getAttribute("moonid").getValue();
var solarSystemLookup = UrlFetchApp.fetch("https://www.fuzzwork.co.uk/api/mapdata.php?itemid="+moonID+"&format=xml").getContentText();
var SS_XML = Xml.parse(solarSystemLookup,true);
var solarSystemName = SS_XML.eveapi.row.getElements("solarsystemname")[0].getText()
var moonName = SS_XML.eveapi.row.getElements("itemname")[0].getText();
var fuel_remain = 0;
var chrt_remain = 0;
var strt_remain = 0;
var fuel_time_h = 0;
var strt_time_h = 0;
if(can_POSDetails)
{
parameters = {
method : "post",
payload :
"keyID=" + encodeURIComponent(keyID) +
"&vCode=" + encodeURIComponent(vCode) +
"&itemID=" + encodeURIComponent(towerID),
user_agent : "Lockefox @HLIBindustry GDOC scripts",
};
api_query = API_addr+"corp/StarbaseDetail.xml.aspx?";
var det_api = UrlFetchApp.fetch(api_query, parameters).getContentText();
var detXML = Xml.parse(det_api,true);
var detList = detXML.eveapi.result.rowset.getElements("row");
for(var invRow = 0; invRow < detList.length; invRow++)
{
var contents_id = detList[invRow].getAttribute("typeid").getValue();
var quantity = Number(detList[invRow].getAttribute("quantity").getValue());
if (contents_id == stront)
strt_remain = quantity;
else if (charters.indexOf(contents_id) > -1)
chrt_remain = quantity;
else if (fuelBlocks.indexOf(contents_id) > -1)
fuel_remain = quantity;
}
var fuel_hours = Math.floor(fuel_remain/(fuel_perhour_conv[towerTypeID]));
fuel_time_h = fuel_hours;
strt_time_h = Math.floor(strt_remain/(stront_perhour_conv[towerTypeID]))
/*--TODO: DO SOV lookup and charter Fuel Math--*/
}
if (verbose_bool) tower_line.push(Number(towerID));
if (can_Locations) tower_line.push( towerName);
if (verbose_bool) tower_line.push(Number(towerTypeID));
tower_line.push( POS_typeID_conv[towerTypeID]);
if (verbose_bool) tower_line.push(Number(solarSystemID));
tower_line.push( solarSystemName);
if (verbose_bool) tower_line.push(Number(moonID));
tower_line.push( moonName);
tower_line.push( POS_status[Number(POSList[towerNum].getAttribute("state").getValue())]);
if (verbose_bool) tower_line.push( POSList[towerNum].getAttribute("statetimestamp"));
if (verbose_bool) tower_line.push( POSList[towerNum].getAttribute("onlinetimestamp"));
if (verbose_bool) tower_line.push( POSList[towerNum].getAttribute("standingownerid"));
if (verbose_bool) tower_line.push( POSList[towerNum].getAttribute("standingownerid"));
if (can_POSDetails) tower_line.push( fuel_remain);
if (can_POSDetails) tower_line.push( chrt_remain);
if (can_POSDetails) tower_line.push( strt_remain);
if (can_POSDetails) tower_line.push( fuel_time_h);
if (can_POSDetails) tower_line.push( strt_time_h);
return_array.push(tower_line);
}
return return_array;
}
function getFacilities(keyID, vCode, header_bool, verbose_bool, test_server)
{
/////Check if key can do the ID->name conversion/////
try{
var can_Locations = true;
API_validateKey(keyID, vCode, "Corporation", 16777216, test_server);
}catch(err){
can_Locations = false;
}
try{
API_validateKey(keyID, vCode, "Corporation", 2, test_server);//foxfour says says accessMask corp/facilities = /corp/assets
}catch(err){
return err;
}
////SET UP ADDRESS CALL////
parameters = {
method : "post",
payload :
"keyID=" + encodeURIComponent(keyID) +
"&vCode=" + encodeURIComponent(vCode),
user_agent : "Lockefox @HLIBindustry GDOC scripts",
};
Utilities.sleep(1000);
var API_addr = "";
var call_mod = "";
//switch call for test/live server
if(test_server) API_addr = "https://api.testeveonline.com/";
else API_addr = "https://api.eveonline.com/";
var api_query = API_addr+"corp/Facilities.xml.aspx?"//keyID="+keyID+"&vCode="+vCode;
var fac_api = UrlFetchApp.fetch(api_query, parameters).getContentText();
var facXML = Xml.parse(fac_api,true);
var facList = facXML.eveapi.result.rowset.getElements("row");
var return_array = [];
if(header_bool)
{
var header = []
if (verbose_bool) header.push("facilityID");
if (can_Locations) header.push("facilityName");
if (verbose_bool) header.push("typeID");
header.push("typeName");
if (verbose_bool) header.push("solarSystemID");
header.push("solarSystemName");
if (verbose_bool) header.push("regionID");
header.push("regionName");
if (verbose_bool) header.push("starbaseModifier");
header.push("tax");
/*--TODO: publish facility bonuses?--*/
return_array.push(header);
}
var facName_conv = {};
if(can_Locations)
{//process whole list, and pull names all at once.
var ID_list = [];
for (var rowNum = 0; rowNum < facList.length; rowNum++)
{//get all facility id's
//ID_list = ID_list+facList[rowNum].getAttribute("facilityid").getValue()+",";
ID_list.push(facList[rowNum].getAttribute("facilityid").getValue());
}
if (facList.length > 0)
facName_conv = getLocations(keyID, vCode, ID_list.join(), test_server);
}
for (var rowNum = 0; rowNum < facList.length; rowNum++)
{
var fac_line = [];
var facID = facList[rowNum].getAttribute("facilityid").getValue();
var facName = facName_conv[facID];
if (verbose_bool) fac_line.push(Number(facID));
if (can_Locations) fac_line.push( facName);
if (verbose_bool) fac_line.push(Number(facList[rowNum].getAttribute("typeid").getValue()));
fac_line.push( facList[rowNum].getAttribute("typename").getValue());
if (verbose_bool) fac_line.push(Number(facList[rowNum].getAttribute("solarsystemid").getValue()));
fac_line.push( facList[rowNum].getAttribute("solarsystemname").getValue());
if (verbose_bool) fac_line.push(Number(facList[rowNum].getAttribute("regionid").getValue()));
fac_line.push( facList[rowNum].getAttribute("regionname").getValue());
if (verbose_bool) fac_line.push(Number(facList[rowNum].getAttribute("starbasemodifier").getValue()));
fac_line.push(Number(facList[rowNum].getAttribute("tax").getValue()));
/*--TODO: publish facility bonuses?--*/
return_array.push(fac_line);
}
return return_array;
}
function getLocations(keyID, vCode, csv_ID_list, test_server)
{
var id_to_name = {};
try{
API_validateKey(keyID, vCode, "Corporation", 16777216, test_server);
}catch(badkey){
throw badkey;
}
parameters = {
method : "post",
payload :
"keyID=" + encodeURIComponent(keyID) +
"&vCode=" + encodeURIComponent(vCode) +
"&IDs=" + encodeURIComponent(csv_ID_list),
user_agent : "Lockefox @HLIBindustry GDOC scripts",
};
Utilities.sleep(1000);
var API_addr="";
if(test_server) API_addr = "https://api.testeveonline.com/";
else API_addr = "https://api.eveonline.com/";
var name_query = API_addr+"corp/Locations.xml.aspx?";
var name_api = UrlFetchApp.fetch(name_query, parameters).getContentText();;
var nameXML = Xml.parse(name_api,true);
var nameList = nameXML.eveapi.result.rowset.getElements("row");
for (var itemNum = 0; itemNum < nameList.length; itemNum ++)
{
var itemID = nameList[itemNum].getAttribute("itemid").getValue();
var itemName = nameList[itemNum].getAttribute("itemname").getValue();
//NOTE: itemID is a string!!
id_to_name[itemID] = itemName;
}
return id_to_name;
}
function getLocation (keyID, vCode, itemID, test_server)
{
var locations_obj = {};
locations_obj = getLocations(keyID, vCode, itemID, test_server);
return locations_obj[itemID];
}
function getIndustryJobs(keyID, vCode, header_bool, verbose_bool, test_server)
{
try{
var can_Locations = true;
API_validateKey(keyID, vCode, "Corporation", 16777216, test_server);
}catch(err){
can_Locations = false;
}
var personal_or_corp = 0; //0=personal, 1=corp
try{
API_validateKey(keyID, vCode, "Character", 128, test_server);
}catch(err){
personal_or_corp = 1;
try{
API_validateKey(keyID, vCode, "Corporation", 128, test_server);
}catch(badkey){
return badkey;
}
}
////SET UP ADDRESS CALL////
parameters = {
method : "post",
payload :
"keyID=" + encodeURIComponent(keyID) +
"&vCode=" + encodeURIComponent(vCode),
user_agent : "Lockefox @HLIBindustry GDOC scripts",
};
Utilities.sleep(1000);
var API_addr = "";
var call_mod = "";
//switch call for personal/corp
if (personal_or_corp == 0) call_mod = "char";
else call_mod = "corp";
//switch call for test/live server
if(test_server) API_addr = "https://api.testeveonline.com/";
else API_addr = "https://api.eveonline.com/";
var api_query = API_addr+call_mod+"/IndustryJobs.xml.aspx?"//keyID="+keyID+"&vCode="+vCode;
var job_api = UrlFetchApp.fetch(api_query, parameters).getContentText();;
var jobXML = Xml.parse(job_api,true);
var jobList = jobXML.eveapi.result.rowset.getElements("row");
var return_array = [];
if(header_bool)
{
var header = []
if (verbose_bool) header.push("jobID");
if (verbose_bool) header.push("installerID");
header.push("installerName");
if (verbose_bool) header.push("facilityID");
header.push("facilityName");
if (verbose_bool) header.push("solarSystemID");
header.push("solarSystemName");
if (verbose_bool) header.push("stationID");
header.push("stationName");
if (verbose_bool) header.push("activityID");
header.push("activity");
if (verbose_bool) header.push("blueprintID");
header.push("blueprintTypeID");
header.push("blueprintTypeName");
if (verbose_bool) header.push("blueprintLocationID");
if (verbose_bool) header.push("outputLocationID");
header.push("runs");
header.push("cost");
header.push("teamID");
if (verbose_bool) header.push("licensedRuns");
if (verbose_bool) header.push("probability");
if (verbose_bool) header.push("productTypeName");
header.push("status");
header.push("timeInSeconds");
header.push("startDate");
header.push("endDate");
if (verbose_bool) header.push("pauseDate");
if (verbose_bool) header.push("completedDate");
if (verbose_bool) header.push("completedCharacterID");
return_array.push(header);
}
var location_lookup = {};
for (var jobNum = 0; jobNum < jobList.length; jobNum++)
{
job_line = [];
var activityID = Number(jobList[jobNum].getAttribute("activityid").getValue());
var activityName = "";
try{
activityName = jobType_arr[activityID];
}catch (err){
activityName = "UKN ACTIVITYID";
}
var facilityID = jobList[jobNum].getAttribute("facilityid").getValue();
var stationID = jobList[jobNum].getAttribute("stationid").getValue();
var facilityName = "";
var stationName = "";
if (facilityID in location_lookup)
facilityName = location_lookup[facilityID]
else
{
var facilityName_lookup = "";
try{
var NPCfac_lookup = UrlFetchApp.fetch("https://www.fuzzwork.co.uk/api/mapdata.php?itemid="+facilityID+"&format=xml").getContentText();
var NPCfacXML = Xml.parse(NPCfac_lookup,true);
facilityName_lookup = NPCfacXML.eveapi.row.getElements("itemname")[0].getText();
}catch (err1){
//Value wasn't an NPC space
//THIS PROBABLY WON'T WORK FOR OUTPOSTS
if(can_Locations)
{
facilityName_lookup = getLocation(keyID, vCode, facilityID, test_server);
}
else
{//BLANK rather than spam
facilityName_lookup = ""
}
}
location_lookup[facilityID] = facilityName_lookup;
facilityName = facilityName_lookup;
}
if (stationID in location_lookup)
stationName = location_lookup[stationID]
else
{
var stationID_lookup = "";
try{
var NPCfac_lookup = UrlFetchApp.fetch("https://www.fuzzwork.co.uk/api/mapdata.php?itemid="+stationID+"&format=xml").getContentText();
var NPCfacXML = Xml.parse(NPCfac_lookup,true);
stationID_lookup = NPCfacXML.eveapi.row.getElements("itemname")[0].getText();
}catch (err1){
//Value wasn't an NPC space
//THIS PROBABLY WON'T WORK FOR OUTPOSTS
if(can_Locations)
{
stationID_lookup = getLocation(keyID, vCode, stationID, test_server);
}
else
{//BLANK rather than spam
stationID_lookup = "NO LOOKUP"
}
}
location_lookup[stationID] = stationID_lookup;
stationName = stationID_lookup;
}
//no smart casing, lower case only for attribute ID's//
if (verbose_bool) job_line.push(Number(jobList[jobNum].getAttribute("jobid").getValue()));
if (verbose_bool) job_line.push(Number(jobList[jobNum].getAttribute("installerid").getValue()));
job_line.push( jobList[jobNum].getAttribute("installername").getValue());
if (verbose_bool) job_line.push(Number(facilityID));
job_line.push( facilityName);
if (verbose_bool) job_line.push(Number(jobList[jobNum].getAttribute("solarsystemid").getValue()));
job_line.push( jobList[jobNum].getAttribute("solarsystemname").getValue());
if (verbose_bool) job_line.push(Number(stationID));
job_line.push( stationName);
/*------------*/
if (verbose_bool) job_line.push(Number(activityID));
job_line.push(activityName);
/*------------*/
if (verbose_bool) job_line.push(Number(jobList[jobNum].getAttribute("blueprintid").getValue()));
job_line.push(Number(jobList[jobNum].getAttribute("blueprinttypeid").getValue()));
job_line.push( jobList[jobNum].getAttribute("blueprinttypename").getValue());
if (verbose_bool) job_line.push(Number(jobList[jobNum].getAttribute("blueprintlocationid").getValue()));
if (verbose_bool) job_line.push(Number(jobList[jobNum].getAttribute("outputlocationid").getValue()));
job_line.push(Number(jobList[jobNum].getAttribute("runs").getValue()));
job_line.push(Number(jobList[jobNum].getAttribute("cost").getValue()));
job_line.push(Number(jobList[jobNum].getAttribute("teamid").getValue()));
if (verbose_bool) job_line.push(Number(jobList[jobNum].getAttribute("licensedruns").getValue()));
if (verbose_bool) job_line.push(Number(jobList[jobNum].getAttribute("probability").getValue()));
if (verbose_bool) job_line.push( jobList[jobNum].getAttribute("producttypename").getValue());
/*TODO ID->STR*/ job_line.push(Number(jobList[jobNum].getAttribute("status").getValue()));
job_line.push(Number(jobList[jobNum].getAttribute("timeinseconds").getValue()));
job_line.push( jobList[jobNum].getAttribute("startdate").getValue());
job_line.push( jobList[jobNum].getAttribute("enddate").getValue());
if (verbose_bool) job_line.push( jobList[jobNum].getAttribute("pausedate").getValue());
if (verbose_bool) job_line.push( jobList[jobNum].getAttribute("completeddate").getValue());
if (verbose_bool) job_line.push(Number(jobList[jobNum].getAttribute("completedcharacterid").getValue()));
return_array.push(job_line);
}
return return_array;
}
function getSkills(keyID, vCode, characterID, production_skills, science_skills, refining_skills, test_server)
{
if (typeof characterID == 'undefined')
throw 'need characterID';
if (typeof production_skills == 'undefined')
production_skills = true;
if (typeof science_skills == 'undefined')
science_skills = true;
if (typeof refining_skills == 'undefined')
refining_skills = true;
if (typeof test_server == 'undefined')
test_server = false;
try{
var can_Locations = true;
API_validateKey(keyID, vCode, "Character", 8, test_server);
}catch (badkey){
return badkey;
}
parameters = {
method : "post",
payload :
"keyID=" + encodeURIComponent(keyID) +
"&vCode=" + encodeURIComponent(vCode) +
"&characterID=" + encodeURIComponent(characterID),
user_agent : "Lockefox @HLIBindustry GDOC scripts",
};
Utilities.sleep(1000);
var API_addr = "";
var call_mod = "char";
if(test_server) API_addr = "https://api.testeveonline.com/";
else API_addr = "https://api.eveonline.com/";
var api_query = API_addr+call_mod+"/CharacterSheet.xml.aspx?"//keyID="+keyID+"&vCode="+vCode;
var char_api = UrlFetchApp.fetch(api_query, parameters).getContentText();;
var charXML = Xml.parse(char_api,true);
var findRowset = charXML.eveapi.result.getElements("rowset");
var skills_indx = 0;
for (skills_indx = 0; skills_indx < findRowset.length; skills_indx++)
{
//debug.push(findRowset[skills_indx].getAttribute("name").getValue());
if(findRowset[skills_indx].getAttribute("name").getValue() == "skills")
break; //set skill_indx to whatever index we find "skills"
}
if (skills_indx >= findRowset.length)
throw "unable to find 'skills' subset on char sheet";
var skillList = charXML.eveapi.result.rowset[skills_indx].getElements("row");
var return_array = [];
for(var skill_row = 0; skill_row < skillList.length; skill_row++)
{
var skillID = Number(skillList[skill_row].getAttribute("typeid").getValue());
var skill_lvl = Number(skillList[skill_row].getAttribute("level").getValue());
var tmp_row = [];
var groupID = 0
if (skillID in skill_name_lookup)
tmp_row.push(skill_name_lookup[skillID]);
else
continue;
tmp_row.push(skill_lvl);
if (skillID in skill_group_lookup)
groupID = skill_group_lookup[skillID];
else
continue;
if (groupID == 268 && production_skills)
return_array.push(tmp_row);
else if (groupID == 270 && science_skills)
return_array.push(tmp_row);
else if (groupID == 1218 && refining_skills)
return_array.push(tmp_row);
}
return return_array;
}
function getAvgVolume(days,item_id,region_id)
{
var market_obj = {};
market_obj = __fetchCrest_market(region_id,item_id);
var date_range = [];
date_range = date_array(days);
var volumes = 0;
for (var index = 0; index < market_obj["items"].length; index ++)
{
var API_date = market_obj["items"][index]["date"];
for (var indx2 = 0; indx2 < date_range.length; indx2++)
{
if (date_range[indx2] == API_date)
{
volumes += market_obj["items"][index]["volume"];
break;
}
}
}
return volumes/days;
}
function getCRESTprices(item_id, region_id, header_bool)
{
var market_obj = {};
market_obj = __fetchCrest_market(region_id,item_id);
var return_struct = [];
if(header_bool)
{
row = []
row.push("date");
row.push("lowPrice");
row.push("highPrice");
row.push("avgPrice");
row.push("volume");
row.push("orderCount");
return_struct.push(row);
}
for (var index = 0; index < market_obj["items"].length; index++)
{
var row = [];
row.push(market_obj["items"][index]["date"]);
row.push(market_obj["items"][index]["lowPrice"]);
row.push(market_obj["items"][index]["highPrice"]);
row.push(market_obj["items"][index]["avgPrice"]);
row.push(market_obj["items"][index]["volume"]);
row.push(market_obj["items"][index]["orderCount"]);
return_struct.push(row);
}
return return_struct;
}
function group_getAvgVolume(days,item_id_list,region_id)
{
var return_list = [];
var item_list = new Array();
item_id_list.forEach (function(row){
row.forEach (function(cell){
if(typeof(cell) === 'number'){
item_list.push(cell);
}
});
});
var cleanTypeIds = new Array();
cleanTypeIds = item_list.filter(function(v,i,a) {
return a.indexOf(v)===i;
});
for (var index=0; index < cleanTypeIds.length; index++)
{
var avgVol = getAvgVolume(days,cleanTypeIds[index],region_id)
return_list.push(avgVol)
//Utilities.sleep(100)
}
return return_list
}
function getVolumes(days,item_id,region_id)
{
var market_obj = {};
market_obj = __fetchCrest_market(region_id,item_id);
var date_range = [];
date_range = date_array(days);
var volumes = [];
for (var index = 0; index < market_obj["items"].length; index ++)
{
var API_date = market_obj["items"][index]["date"];
for (var indx2 = 0; indx2 < date_range.length; indx2++)
{
if (date_range[indx2] == API_date)
{
volumes.push(market_obj["items"][index]["volume"]);
break;
}
}
}
return volumes;
}