forked from mcl8on/MMM-PGA
-
Notifications
You must be signed in to change notification settings - Fork 2
/
OWGR.js
45 lines (37 loc) · 1.41 KB
/
OWGR.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
const request = require('node-fetch');
const flags = require('./flags.js');
module.exports = {
url: "http://www.owgr.com/ranking/",
rapidUrl: 'https://golf-leaderboard-data.p.rapidapi.com/world-rankings',
async getOWGRData(maxPlayers, rapidAPIKey, callback) {
var rapidKey = rapidAPIKey;
const response = await fetch(this.rapidUrl, {
method: 'GET',
headers: {
'X-RapidAPI-Key': rapidKey,
'X-RapidAPI-Host': 'golf-leaderboard-data.p.rapidapi.com'
}
})
const data = await response.json();
var owgrRanking = {
pointsHeading: "Average Points",
rankings: []
};
var payload = data;
if (payload.results.rankings.length > 1) {
for (var i = 0; i < payload.results.rankings.length; i++) {
flagName = payload.results.rankings[i].player_name.replace(/\s/g, '');
owgrRanking.rankings.push({
"name": payload.results.rankings[i].player_name,
"curPosition": payload.results.rankings[i].position,
"lwPosition": "1",
"points": payload.results.rankings[i].total_points,
"flagUrl": flags.getFlagURL(flagName)
});
if (i == maxPlayers)
break;
}
}
callback(owgrRanking);
}
}