-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
executable file
·62 lines (53 loc) · 1.85 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
// IMPORTS
const lineReader = require('line-reader');
const fs = require('fs');
const path = require('path');
const Clockify = require('clockify-npm');
const moment = require('moment');
// CONSTS
const endOfDocument = '=EOD=';
const documentName = 'daily-time-entry.txt';
const timeFormat = 'yyyy-MM-DDTHH:mm:ss';
const apiKey = 'YOUR_KEY';
const userId = 'YOUR_USER_ID';
const workspaceId = ''; // Bliss 2023
const projectId = ''; // App moey!
const taskId = ''; // iOS Development
// PROGRAM
Clockify.SetKey(apiKey);
function optionsForLine(line) {
let params = line.split('|');
let timeParams = params[1].split('-');
let startTime = timeParams[0].split(':');
let endTime = timeParams[1].split(':');
let days = 0
//let type = 'days'
let type = 'hours'
let description = params[0]; // Nome da entrada
let startDate = moment().hours(startTime[0]).minutes(startTime[1]).seconds(0).subtract(days, type).utcOffset(0); // Hora de início
let endDate = moment().hours(endTime[0]).minutes(endTime[1]).seconds(0).subtract(days, type).utcOffset(0); // Hora de fim
return {
taskId: taskId,
projectId: projectId,
billable: true,
description: description,
start: startDate.format(timeFormat) + 'Z',
end: endDate.format(timeFormat) + 'Z'
};
}
function addTimeEntries(entries) {
Promise.all(entries).then(() => {
console.log('All done! 👍');
}).catch(error => {
console.error(`Whoops! Something went wrong: ${error}`);
});
}
let entries = [];
lineReader.eachLine(`${path.dirname(require.main.filename)}/${documentName}`, function(line) {
if (line.includes(endOfDocument)) {
addTimeEntries(entries);
return false;
}
entries.push(Clockify.Workspaces.addTimeEntry(workspaceId, optionsForLine(line)));
// console.log(optionsForLine(line))
});