-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetData.js
More file actions
35 lines (31 loc) · 985 Bytes
/
Copy pathgetData.js
File metadata and controls
35 lines (31 loc) · 985 Bytes
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
import API from 'call-of-duty-api'
const codAPI = API()
//const codAPI = require('call-of-duty-api')();
const COD_USERNAME = process.env.COD_USERNAME;
const COD_PASSWORD = process.env.COD_PASSWORD;
function toDateTime(secs) {
var t = new Date(Date.UTC(1970, 0, 1)); // Epoch
t.setUTCSeconds(secs);
return t;
}
const isToday = (someDate) => {
const today = new Date()
return someDate.getDate() == today.getDate() &&
someDate.getMonth() == today.getMonth() &&
someDate.getFullYear() == today.getFullYear()
}
async function getData(id){
await codAPI.login(COD_USERNAME, COD_PASSWORD);
//let data = await codAPI.MWwz(id, 'acti');
let data4 = await codAPI.MWcombatwz(id, 'acti');
let kills = 0
let deaths = 0
data4.matches.forEach((i) => {
if(isToday(toDateTime(i.utcStartSeconds)) && i.gameType === 'wz'){
kills+= i.playerStats.kills;
deaths+= i.playerStats.deaths;
}
})
return (kills/deaths).toFixed(2)
}
export default getData;