-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathkaggle.js
31 lines (26 loc) · 949 Bytes
/
kaggle.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
const axios = require("axios");
const { kaggleUsername, kaggleApiKey } = require("../../secrets.json");
const { parserErrorHandler, getCurrentTimeInSeconds } = require('./../utils');
const KAGGLE_API_URL = "https://www.kaggle.com/api/v1/competitions/list";
const KAGGLE = 'kaggle';
const isContestActive = (currentTimeInSeconds) => contest => contest.endTime > currentTimeInSeconds
const convertToStandardContest = contest => ({
name: contest.title,
url: contest.url,
platform: KAGGLE,
startTime: Date.parse(contest.enabledDate) / 1000,
endTime: Date.parse(contest.deadline) / 1000,
});
const kaggle = () => axios.get(KAGGLE_API_URL, {
timeout: 15000,
auth: {
username: kaggleUsername,
password: kaggleApiKey,
},
})
.then(response => response.data
.map(convertToStandardContest)
.filter(isContestActive(getCurrentTimeInSeconds()))
)
.catch(parserErrorHandler(KAGGLE));
module.exports = kaggle;