-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprototype.js
executable file
·41 lines (31 loc) · 1.22 KB
/
prototype.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
#!/usr/bin/env node
'use strict';
const request = require('request'); // https://github.com/request/request
const _ = require('underscore'); // http://underscorejs.org/
const verbose = ((process.argv.indexOf('-v') > 0) || (process.argv.indexOf('--verbose') > 0));
function isToday(obj) {
const today = new Date();
return (new Date(obj.created_at)).getYear() === today.getYear() &&
(new Date(obj.created_at)).getMonth() === today.getMonth() &&
(new Date(obj.created_at)).getDate() === today.getDate();
}
const USER_NAME = 'philbobaggins'; // TODO: Get from command line arguments
const options = {
uri: 'https://api.github.com/users/' + USER_NAME + '/events',
headers: { 'User-Agent': 'did-i-github-today-prototype' }
};
request(options, function(error, response, body) {
// TODO: Check response.statusCode and error variables
const events = JSON.parse(body);
const todaysEvents = _.filter(events, isToday);
if (verbose) {
for (var i = 0; i < todaysEvents.length; i++) {
console.log(todaysEvents[i].type +' at ' + todaysEvents[i].created_at);
}
}
if (_.any(todaysEvents)) {
console.log('Yes');
} else {
console.log('No');
}
});