-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfifa.js
45 lines (40 loc) · 1.33 KB
/
fifa.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
#!/usr/bin/env node
var program = require('commander');
var request = require('request');
var chalk = require('chalk');
var cliff = require('cliff');
var url = "http://worldcup.sfg.io/matches/today";
var matchInfo;
request({
method: 'GET',
url: url,
callback: program_check
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
matchInfo = JSON.parse(body);
program_check();
} else if (error) {
console.log(chalk.red('Error: ' + error));
process.exit(1);
}
});
program
.version('1.1.2')
.option('-t, --today', "Return today's match scores and timings")
.parse(process.argv);
function program_check() {
if (program.today) {
var rows = [];
rows.push(["Home ".bold, "Score ".bold, "Away ".bold, "Status".bold]);
for(var i = 0; i < matchInfo.length; i++) {
var matchObj = matchInfo[i];
var home_team = matchObj["home_team"];
var away_team = matchObj["away_team"];
var score = home_team["goals"] + " - " + away_team["goals"];
rows.push([home_team["country"].toString() + " ", score.toString() + " ", away_team["country"].toString() + " ", matchObj["status"]]);
}
console.log(cliff.stringifyRows(rows));
} else {
program.help();
}
}