-
Notifications
You must be signed in to change notification settings - Fork 0
/
movedata.js
152 lines (131 loc) · 4.04 KB
/
movedata.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
var data = require('promised-rest-client')({
url: 'http://services.faa.gov/'
});
var refocus = require('promised-rest-client')({
url: 'http://refocus.internal.salesforce.com/'
});
var iataList = {};
function updateMessage(iata) {
data.get({
url: 'airport/status/' + iata
, qs: {
format: 'application/json'
}
}).then(function (resp) {
refocus.post({
url: 'v1/samples/upsert'
, body: {
"name": iataList[resp.IATA].sample
, "messageCode": resp.status.reason.substr(0, 5)
, "messageBody": resp.status.reason + " // " + resp.status.type
}
}).catch(function(resp){
console.log("Error sending sample.");
});
}).catch(function (resp) {
console.log("Error: " + resp.message);
});
}
var sampleUpsertArray = [];
data.get({
url: 'airport/list'
, qs: {
format: 'application/json'
}
}).then(function (resp) {
for (i=0;i<resp.length;i++){
var rootAbsolutePath = "Demos.Airports";
var rootSubject = {
isPublished: true
, name: rootAbsolutePath
};
var state = resp[i].STATE.replace(/\s/g, '');
var stateAbsolutePath = rootAbsolutePath;
var stateSubject = {
isPublished: true
, name: state
, parentAbsolutePath: stateAbsolutePath
};
var city = resp[i].CITY.replace(/[^a-zA-Z]/g, '');
var cityAbsolutePath = stateAbsolutePath + "." + state;
var citySubject = {
isPublished: true
, name: city
, parentAbsolutePath: cityAbsolutePath
};
var iata = resp[i].IATA;
var airport = iata;
var airportAbsolutePath = cityAbsolutePath + "." + city;
var airportSubject = {
isPublished: true
, name: airport
, parentAbsolutePath: airportAbsolutePath
};
var CREATE_SUBJECTS = false;
if (CREATE_SUBJECTS) {
refocus.post({
url: 'v1/subjects'
, body: rootSubject
}).catch(function (resp) {
console.log("Error: " + resp.message);
});
refocus.post({
url: 'v1/subjects'
, body: stateSubject
}).catch(function (resp) {
console.log("Error: " + resp.message);
});
refocus.post({
url: 'v1/subjects'
, body: citySubject
}).catch(function (resp) {
console.log("Error: " + resp.message);
});
refocus.post({
url: 'v1/subjects'
, body: airportSubject
}).catch(function (resp) {
console.log("Error: " + resp.message);
});
}
//if there is a delay then get the details
var hasDelay = "true";
if (resp[i].DELAYCOUNT > 0) {
hasDelay = "false";
}
var airportSubjectPath = airportSubject.parentAbsolutePath + "." + airportSubject.name;
var links = [{
"name": airportSubject.name + " Delays"
, "url": resp[i].URI + "?format=application/json"
}];
var sampleName = airportSubjectPath + "|AIRPORTDELAY";
var sampleUpsertBody = {
"name": sampleName
, "relatedLinks": links
, "value": hasDelay
};
sampleUpsertArray.push(sampleUpsertBody);
if (hasDelay == "false") {
iataList[iata] = {
"sample": sampleName
};
}
}
}).then(function (resp) {
console.log(sampleUpsertArray.length);
var queryStart = new Date();
refocus.post({
url: 'v1/samples/upsert/bulk'
, body: sampleUpsertArray,
}).catch(function(resp) {
console.log(resp);
}).then(function(resp) {
var queryEnd = new Date() - queryStart;
console.log('end query - ' + queryEnd);
});
for (iata in iataList) {
updateMessage(iata);
}
}).catch(function (err) {
console.error(err);
})