-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMatchIndex.js
50 lines (46 loc) · 1.73 KB
/
MatchIndex.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
//fetching the Match Id from the URI link
const { matchStats } = require("./MatchData");
const request = require('request-promise-native');
const inquirer = require('inquirer');
const LIVE_MATCHES = 'https://www.cricbuzz.com/match-api/livematches.json';
const checkMatchAndDisplay = (options) => {
request({
uri: LIVE_MATCHES,
json: true,
})
.then(({ matches }) => {
const matchIds = Object.keys(matches);
const internationals = matchIds.filter(id => matches[id].series.category === 'International');
const matchOptions = internationals.map(id => {
const match = matches[id];
return {
name: `${match.team1.name} v ${match.team2.name} in ${match.series.name}`,
value: match.id,
short: `${match.team1.s_name} v ${match.team2.s_name}`,
};
});
const questions = [
{
type: 'list',
name: 'matchNumber',
message: 'Choose which match to track scores for:',
choices: matchOptions,
}
];
return inquirer.prompt(questions);
})
.then(answers => {
const matchUrlLink = `https://www.cricbuzz.com/match-api/${answers.matchNumber}/commentary.json`;
if (options.includes('lu')) {
matchStats(matchUrlLink, options);
setInterval(() => {
// clear console and set up a new queued object
process.stdout.write('\u001B[2J\u001B[0;0f');
matchStats(matchUrlLink, options);
}, options.frequency || 30000);
} else {
matchStats(matchUrlLink, options);
}
});
}
module.exports = { checkMatchAndDisplay }