forked from fuzzysteve/eve-googledocs-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HistoryGrabber.gs
105 lines (83 loc) · 2.71 KB
/
HistoryGrabber.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
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
function loadAllVolumes(typeID,regionID){
if (typeof regionID == 'undefined'){
regionID=10000002;
}
if (typeof typeID == 'undefined'){
throw 'need typeid';
}
var prices = new Array();
var url="https://crest-tq.eveonline.com/market/"+regionID+"/history/?type=https://crest-tq.eveonline.com/inventory/types/"+typeID+"/";
var parameters = {method : "get", payload : ""};
var jsonFeed = UrlFetchApp.fetch(url, parameters).getContentText();
data = JSON.parse(jsonFeed)
var volumes = new Array();
if (data) {
for (var i = 0; i < data.items.length; i++) {
volumes.push(data.items[i].volume);
}
}
return volumes;
}
function zeroFill( number, width )
{
width -= number.toString().length;
if ( width > 0 )
{
return new Array( width + (/\./.test( number ) ? 2 : 1) ).join( '0' ) + number;
}
return number + ""; // always return a string
}
function loadVolume(typeID,regionID){
if (typeof regionID == 'undefined'){
regionID=10000002;
}
if (typeof typeID == 'undefined'){
throw 'need typeid';
}
var prices = new Array();
var url="https://crest-tq.eveonline.com/market/"+regionID+"/history/?type=https://crest-tq.eveonline.com/inventory/types/"+typeID+"/";
var parameters = {method : "get", payload : ""};
var jsonFeed = UrlFetchApp.fetch(url, parameters).getContentText();
var volumes = new Array();
data = JSON.parse(jsonFeed)
var d = new Date();
d.setDate(d.getDate() - 1);
month=d.getMonth()+1;
yesterday=d.getFullYear()+"-"+zeroFill(month,2)+"-"+zeroFill(d.getDate(),2)+"T00:00:00";
if (data) {
for (var i = 0; i < data.items.length; i++) {
if (data.items[i].date == yesterday) {
volumes.push(data.items[i].volume);
}
}
}
return volumes;
}
function loadThirtyDayVolume(typeID,regionID){
if (typeof regionID == 'undefined'){
regionID=10000002;
}
if (typeof typeID == 'undefined'){
throw 'need typeid';
}
var prices = new Array();
var url="https://crest-tq.eveonline.com/market/"+regionID+"/history/?type=https://crest-tq.eveonline.com/inventory/types/"+typeID+"/";
var parameters = {method : "get", payload : ""};
var jsonFeed = UrlFetchApp.fetch(url, parameters).getContentText();
var volumes = new Array();
data = JSON.parse(jsonFeed)
var d = new Date();
time=Date.UTC(d.getFullYear(),d.getMonth()+1,d.getDate())
from = time - 2.592e+9
if (data) {
for (var i = 0; i < data.items.length; i++) {
year=data.items[i].date.substring(0,4)
month=data.items[i].date.substring(5,7)
day=data.items[i].date.substring(8,10)
if (Date.UTC(year,month,day) >= from) {
volumes.push(data.items[i].volume)
}
}
}
return volumes;
}