-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetUniversalTimes.js
103 lines (91 loc) · 4.18 KB
/
GetUniversalTimes.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
// GetUniversalTimes.js
//
// Function: Retrieve every rides wait times once per minute.
//
// Universal Studios Florida
//========================================================================================
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 UniversalStudios = new Themeparks.Parks.UniversalStudiosFlorida({scheduleDaysToReturn:1});
const UniversalIslands = new Themeparks.Parks.UniversalIslandsOfAdventure({scheduleDaysToReturn:1});
const VolcanoBay = new Themeparks.Parks.UniversalVolcanoBay({scheduleDaysToReturn:1});
class UniversalTimes {
constructor(MongoDBObj) {
this.MongoDB = MongoDBObj;
}
GetUSO() {
return new Promise((resolve,reject) => {
if (!this.MongoDB.isConnected()) this.MongoDB.connect();
UniversalStudios.GetWaitTimes().then((rideTimes) => {
DEBUG_MODE && logger.debug("--- Universal Studios -------------------------------------------------------");
rideTimes.forEach((ride) => {
DEBUG_MODE && logger.info(`USO: ${ride.name}: ${ride.waitTime} minutes wait (${ride.status})`);
let rideNameParsed = ride.name.replace(/[!-\/:-@[-`{-~]/g, '');
this.MongoDB.insertOne("Rides", {name:rideNameParsed, time:new Date(), park:'Universal Studios', status:ride.status, waitTime:ride.waitTime});
});
DEBUG_MODE && logger.debug('GetUSO() Complete');
resolve(this);
}).catch((error) => {logger.error(`[${moment().format("MM-DD-YYYY HH:mm:ss")}] GetUSO() failed.`); reject(); });
});
}
GetIOA() {
return new Promise((resolve,reject) => {
if (!this.MongoDB.isConnected()) this.MongoDB.connect();
UniversalIslands.GetWaitTimes().then((rideTimes) => {
DEBUG_MODE && logger.debug("--- Islands of Adventure ------------------------------------------");
rideTimes.forEach((ride) => {
DEBUG_MODE && logger.info(`IOA: ${ride.name}: ${ride.waitTime} minutes wait (${ride.status})`);
let rideNameParsed = ride.name.replace(/[!-\/:-@[-`{-~]/g, '');
this.MongoDB.insertOne("Rides", {name:rideNameParsed, time:new Date(), park:'Islands Of Adventure', status:ride.status, waitTime:ride.waitTime});
});
DEBUG_MODE && logger.debug('GetIOA() Complete');
resolve(this);
}).catch((error) => {logger.error(`[${moment().format("MM-DD-YYYY HH:mm:ss")}] GetIOA() failed.`); reject(); });
});
}
GetVB() {
return new Promise((resolve,reject) => {
if (!this.MongoDB.isConnected()) this.MongoDB.connect();
VolcanoBay.GetWaitTimes().then((rideTimes) => {
DEBUG_MODE && logger.debug("--- Volcano Bay ------------------------------------------");
rideTimes.forEach((ride) => {
DEBUG_MODE && logger.info(`VB: ${ride.name}: ${ride.waitTime} minutes wait (${ride.status})`);
let rideNameParsed = ride.name.replace(/[!-\/:-@[-`{-~]/g, '');
this.MongoDB.insertOne("Rides", {name:rideNameParsed, time:new Date(), park:'Volcano Bay', status:ride.status, waitTime:ride.waitTime});
});
DEBUG_MODE && logger.debug('GetVB() Complete');
resolve(this);
}).catch((error) => {logger.error(`[${moment().format("MM-DD-YYYY HH:mm:ss")}] GetVB() failed.`); reject(); });
});
}
}
module.exports = UniversalTimes;