-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyatt.js
111 lines (103 loc) · 3.37 KB
/
hyatt.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
var system = require('system');
var args = system.args;
var DEBUG = true;
var unidecode = require('unidecode');
if(args.length != (1+1) ){
console.log('error: lack of parameters');
phantom.exit();
}
else{
var url = args[1];
var resultObject = {};
var ratio = 1;
var page = require('webpage').create(),
url = url
page.open(url, function (status) {
if (status !== 'success') {
console.log('error: Unable to access network '+ status);
phantom.exit();
} else {
var jsonSource = page.plainText;
resultObject = JSON.parse(jsonSource);
}
page.open("https://native.usablenet.com/ws/hyatt-nat/v3/getCurrency?env=prod&platform=iphone¤cy="+resultObject.currency, function (status) {
if (status !== 'success') {
console.log('error: Unable to access network '+ status);
phantom.exit();
}
else{
jsonSource = page.plainText;
var tempObject = JSON.parse(jsonSource);
ratio = tempObject.ratio
}
result = resultObject.results
for (var i = 0; i < result.length; i++) {
var tempObject = result[i];
// console.log(JSON.stringify(tempObject));
if(tempObject.isSoldOut == true){
tempObject.pp = {point_plan: "No Best Point Plan", value: 0};
tempObject.lsp = 9999;
}else{
tempObject.lsp = tempObject.price/ratio;
tempObject.passportPoint = tempObject.passportPoint.replace(/,/g,'');
tempObject.passportPoint = Number(tempObject.passportPoint);
tempObject.pp = {point_plan: "Points", value: tempObject.lsp/tempObject.passportPoint};
tempObject.points = tempObject.passportPoint;
}
tempObject.detail = {id:tempObject.code, address: tempObject.address, image: tempObject["image"]}
if(tempObject["currency"]){
delete tempObject["currency"];
}
if(tempObject["image"]){
delete tempObject["image"];
}
if(tempObject["passportPoint"]){
delete tempObject["passportPoint"];
}
if(tempObject["isSoldOut"]){
delete tempObject["isSoldOut"];
}
if(tempObject["price"]){
delete tempObject["price"];
}
if(tempObject["colorCode"]){
delete tempObject["colorCode"];
}
if(tempObject["code"]){
delete tempObject["code"];
}
if(tempObject["brand"]){
delete tempObject["brand"];
}
if(tempObject["description"]){
delete tempObject["description"];
}
if(tempObject["phone"]){
delete tempObject["phone"];
}
if(tempObject["distance"]){
delete tempObject["distance"];
}
if(tempObject["address"]){
delete tempObject["address"];
}
if(tempObject["coords"]){
delete tempObject["coords"];
}
if(tempObject["detailsWSUrl"]){
delete tempObject["detailsWSUrl"];
}
if(tempObject["bookingRatesMwUrl"]){
delete tempObject["bookingRatesMwUrl"];
}
}
console.log(JSON.stringify(result));
phantom.exit();
});
// phantom.exit();
});
// phantom.exit();
page.onConsoleMessage = function (msg) {
console.log(msg);
};
}