-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_helper.js
More file actions
149 lines (126 loc) · 4.43 KB
/
node_helper.js
File metadata and controls
149 lines (126 loc) · 4.43 KB
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
/* MagicMirror²
* Module: MMM-PGA
*
* By mcl8on
*
*/
const Log = require('logger')
const NodeHelper = require('node_helper')
const express = require('express') // necessary?
var ESPN = require('./ESPN.js')
const OWGR = require('./OWGR.js')
const FEDEXCUP = require('./FEDEXCUP.js')
module.exports = NodeHelper.create({
requiresVersion: '2.20.0',
start: function () {
Log.log('Starting node_helper for: ' + this.name)
// Does this do anything?
this.expressApp.use(express.urlencoded({ extended: true }))
this.expressApp.post('/MMM-PGA-UpdateFavs', this._onUpdateFavs.bind(this))
},
_onUpdateFavs: function (req, res) {
Log.log('[MMM-PGA] Update favorites')
this.sendSocketNotification('UPDATE_FAVORITES')
res.sendStatus(200)
},
/* // schedules the leaderboard update
scheduleUpdate: function () {
// schedule the updates for Subsequent Loads
var self = this
setInterval(() => {
self.getLeaderboardData()
}, self.config.updateInterval)
}, */
// Schedule the Ranking Updates. This is a much longer intervl since the data only changes weekly
scheduleRankingUpdate: function () {
// schedule the updates for Subsequent Loads
var self = this
setInterval(() => {
self.getRankingData(self.config.maxNumRankings)
}, self.config.rankingsUpdateInterval)
},
// Schedule the Fedex Standings Updates. This is a much longer intervl since the data only changes weekly
scheduleFedexUpdate: function () {
// schedule the updates for Subsequent Loads
var self = this
setInterval(() => {
self.getFedexData(self.config.maxNumRankings)
}, self.config.rankingsUpdateInterval)
},
// Schedule the upcoming tourney updates. This is a much longer interval since the data only changes rarely
scheduleUpcomingTourneyUpdate: function () {
// schedule the updates for Subsequent Loads
var self = this
setInterval(() => {
self.getUpcomingTourneyData(self.config.numTournament)
}, self.config.rankingsUpdateInterval)
},
getLeaderboardData: function () {
var self = this
ESPN.getTournamentData(this.config.updateInterval, this.config.skipChannels, function (tournament) {
self.sendSocketNotification('PGA_RESULT', tournament)
})
if (this.config.showBoards) {
// Log.debug(Math.max(ESPN.boardUpdateInterval, self.config.updateInterval) / 1000 / 60)
setTimeout(() => {
self.getLeaderboardData()
}, Math.max(ESPN.boardUpdateInterval, self.config.updateInterval))
}
},
getUpcomingTourneyData: function (numTournaments) {
var self = this
ESPN.getTournaments(numTournaments, function (tournaments) {
if (tournaments.length > 0) {
self.sendSocketNotification('PGA_TOURNAMENT_LIST', tournaments)
}
else {
Log.debug('[MMM-PGA] No tournament data to post; either no upcoming tournaments, or error fetching data.')
}
})
},
getRankingData: function (maxNumRankings, rapidAPIKey) {
var self = this
OWGR.getOWGRData(maxNumRankings, rapidAPIKey, function (owgrRanking) {
self.sendSocketNotification('OWGR_RANKING', owgrRanking)
})
},
getFedexData: function (maxNumRankings, rapidAPIKey) {
var self = this
// if (this.config.rapidAPIKey !== '') {
FEDEXCUP.getFedExCupData(maxNumRankings, rapidAPIKey, function (fcRanking) {
self.sendSocketNotification('FEDEXCUP_RANKING', fcRanking)
})
// }
},
socketNotificationReceived: function (notification, payload) {
if (notification === 'CONFIG') {
this.config = payload
if (this.started !== true) {
this.started = true
this.scheduleUpcomingTourneyUpdate()
/* if (this.config.showBoards) {
this.scheduleUpdate()
} */
if (this.config.showFedex) {
this.scheduleFedexUpdate()
}
if (this.config.showOWGR) {
this.scheduleRankingUpdate()
}
}
// Load Data to begin with so we dont have to wait for next server load
// Each client will make a call at startup
this.getUpcomingTourneyData(this.config.numTournaments)
var self = this
setTimeout(function () {
self.getLeaderboardData()
}, 4000)
if (this.config.showFedex) {
this.getFedexData(this.config.maxNumRankings, this.config.rapidAPIKey)
}
if (this.config.showOWGR) {
this.getRankingData(this.config.maxNumRankings, this.config.rapidAPIKey)
}
}
},
})