forked from spidasoftware/time-harvester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time-harvester
executable file
·95 lines (73 loc) · 2.29 KB
/
time-harvester
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node
var argv = require('optimist').argv;
console.log("Usage: ")
console.log(" --this: run it for this week.")
console.log(" --last (default): run it for last week.")
// console.log(" --file: Where to pipe the JSON string.")
console.log("")
var numberMap = {
"Development":404,
"Code Review": 409,
"Admin": 402,
"Testing": 405,
"Specification": 403
}
var Harvest = require('harvest')
, harvest = new Harvest({
subdomain: process.env.HARVEST_SUBDOMAIN,
email: process.env.HARVEST_EMAIL,
password: process.env.HARVEST_PASSWORD
})
TimeTracking = harvest.TimeTracking;
var arguments = process.argv.slice(2);
var convertEntryToSpida = function(harvestEntry){
var spent_at = harvestEntry.spent_at.toString()
var spidaEntry = {
day: spent_at[5]+spent_at[6]+"/"+spent_at[8]+spent_at[9]+"/"+spent_at[0]+spent_at[1]+spent_at[2]+spent_at[3],
task:numberMap[harvestEntry.task],
code:harvestEntry.notes.split(" ")[0],
remarks:harvestEntry.notes,
hours:harvestEntry.hours
}
return spidaEntry
}
var weeklyTime = []
if(process.argv.length)
var curr = new Date; // get current date
var first = curr.getDate() - curr.getDay() - 6; // First day is the day of the month - the day of the week
var last = first + 6; // last day is the first day + 6
if(argv.this){
first = first+7;
last = last+7;
}
var firstday = new Date(curr.setDate(first)).toUTCString();
var lastday = new Date(curr.setDate(last)).toUTCString();
console.log("Starting: "+firstday);
console.log("Ending : "+lastday);
// { date: new Date('11/15/2012') }
var timesCalled = 0;
var totalTime = [];
var getDayTime = function(date){
var retrieveDay = new Date()
retrieveDay.setDate(date)
console.log(" getting: "+retrieveDay.toUTCString());
TimeTracking.daily({date:retrieveDay}, function(err, tasks) {
if (err) throw new Error(err);
for (var i = tasks.day_entries.length - 1; i >= 0; i--) {
var harvestEntry = tasks.day_entries[i]
if(harvestEntry.hours>0){
totalTime.push(convertEntryToSpida(harvestEntry))
}
};
if(timesCalled<6){
timesCalled = timesCalled + 1
getDayTime(date+1);
}else{
console.log("Finished");
console.log(JSON.stringify(totalTime));
}
});
}
if(argv.file){
}
getDayTime(first);