-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetDisneyTimes.js
147 lines (131 loc) · 5.32 KB
/
GetDisneyTimes.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
// GetDisneyTimes.js
// Run as service or cronjob
// Function: Retrieve every rides wait times once per minute.
//
// Notes: 525,600 minutes in a year.
//========================================================================================
const dotenv = require('dotenv').config()
const Themeparks = require("themeparks");
const moment = require('moment-timezone');
const MongoDB = require('./MongoDB.js')
const winston = require('winston');
// Logging
const loggerOptions = {
file: {
level: 'debug',
filename: `./index.log`,
handleExceptions: true,
json: true,
maxsize: 5242880, // 5MB
maxFiles: 2,
colorize: false,
},
console: {
level: 'debug',
handleExceptions: true,
json: false,
colorize: true,
}
};
const logger = winston.createLogger({transports: [new winston.transports.File(loggerOptions.file), new winston.transports.Console(loggerOptions.console)], exitOnError: false});
// Settings
Themeparks.Settings.Cache = __dirname + "/themeparks.db";
let DEBUG_MODE = false;
// Environment Variables
if (!process.env.ENVIRONMENT) { logger.error("No ENV file, quitting."); process.exit(); }
if (process.env.ENVIRONMENT == 'dev' || process.env.ENVIRONMENT == 'test') DEBUG_MODE = true;
// Parks - NOTE: Only create parks ONCE
const DisneyWorldMagicKingdom = new Themeparks.Parks.WaltDisneyWorldMagicKingdom({scheduleDaysToReturn:1});
const DisneyWorldAnimalKingdom = new Themeparks.Parks.WaltDisneyWorldAnimalKingdom({scheduleDaysToReturn:1});
const DisneyWorldEpcot = new Themeparks.Parks.WaltDisneyWorldEpcot({scheduleDaysToReturn:1});
const DisneyWorldHollywoodStudios = new Themeparks.Parks.WaltDisneyWorldHollywoodStudios({scheduleDaysToReturn:1});
class DisneyTimes {
constructor(MongoDBObj) {
this.MongoDB = MongoDBObj;
}
GetMK() {
return new Promise((resolve,reject) => {
if (!this.MongoDB.isConnected()) { this.MongoDB.connect(); }
try {
DisneyWorldMagicKingdom.GetWaitTimes().then((rideTimes) => {
DEBUG_MODE && logger.debug("--- Magic Kingdom -------------------------------------------------------");
rideTimes.forEach((ride) => {
DEBUG_MODE && logger.debug(`MK: ${ride.name}: ${ride.waitTime} minutes wait (${ride.status})`);
let rideNameParsed = ride.name.replace(/[!-\/:-@[-`{-~]/g, '');
this.MongoDB.insertOne("Rides", {name:rideNameParsed, time:new Date(), park:'Magic Kingdom', status:ride.status, waitTime:ride.waitTime});
});
DEBUG_MODE && logger.debug('GetMK() complete');
resolve(this);
})
}
catch (error) {
logger.error("Magic Kingdom GetWaitTimes() failed: "+error);
reject(this);
}
});
}
GetAK() {
return new Promise((resolve,reject) => {
if (!this.MongoDB.isConnected()) this.MongoDB.connect();
try {
DisneyWorldAnimalKingdom.GetWaitTimes().then((rideTimes) => {
DEBUG_MODE && logger.debug("--- Animal Kingdom ------------------------------------------------------");
rideTimes.forEach((ride) => {
DEBUG_MODE && logger.debug(`AK: ${ride.name}: ${ride.waitTime} minutes wait (${ride.status})`);
let rideNameParsed = ride.name.replace(/[!-\/:-@[-`{-~]/g, '');
this.MongoDB.insertOne("Rides", {name:rideNameParsed, time:new Date(), park:'Animal Kingdom', status:ride.status, waitTime:ride.waitTime});
});
DEBUG_MODE && logger.debug('GetAK() complete');
resolve(this);
})
}
catch (error) {
logger.error("Animal Kingdom GetWaitTimes() failed: "+error);
reject(this);
}
});
}
GetEpcot() {
return new Promise((resolve,reject) => {
if (!this.MongoDB.isConnected()) this.MongoDB.connect();
try {
DisneyWorldEpcot.GetWaitTimes().then((rideTimes) => {
DEBUG_MODE && logger.debug("--- Epcot ---------------------------------------------------------------");
rideTimes.forEach((ride) => {
DEBUG_MODE && logger.debug(`Epcot: ${ride.name}: ${ride.waitTime} minutes wait (${ride.status})`);
let rideNameParsed = ride.name.replace(/[!-\/:-@[-`{-~]/g, '');
this.MongoDB.insertOne("Rides", {name:rideNameParsed, time:new Date(), park:'Epcot', status:ride.status, waitTime:ride.waitTime});
});
DEBUG_MODE && logger.debug('GetEpcot() complete');
resolve(this);
})
}
catch (error) {
logger.error("Epcot GetWaitTimes() failed: "+error);
reject(this);
}
});
}
GetHS() {
return new Promise((resolve,reject) => {
if (!this.MongoDB.isConnected()) { this.MongoDB.connect(); }
try {
DisneyWorldMagicKingdom.GetWaitTimes().then((rideTimes) => {
DEBUG_MODE && logger.debug("--- Hollywood Studios ----------------------------------------------------");
rideTimes.forEach((ride) => {
DEBUG_MODE && logger.debug(`HS: ${ride.name}: ${ride.waitTime} minutes wait (${ride.status})`);
let rideNameParsed = ride.name.replace(/[!-\/:-@[-`{-~]/g, '');
this.MongoDB.insertOne("Rides", {name:rideNameParsed, time:new Date(), park:'Hollywood Studios', status:ride.status, waitTime:ride.waitTime});
});
DEBUG_MODE && logger.debug('GetHS() complete');
resolve(this);
})
}
catch (error) {
logger.error("Hollywood Studios GetWaitTimes() failed: "+error);
reject(this);
}
});
}
};
module.exports = DisneyTimes;