-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
4,726 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright (c) 2015 Ivan Poddubny | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Zoho People Attendance Report Fetcher | ||
|
||
Zoho People API doesn't have any methods to fetch attendance data reports programmatically. | ||
This tiny script downloads the Custom Attendance Report from Zoho People web interface and emits it as a JSON. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
login: '[email protected]', | ||
password: 'zoho-user-password' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
var needle = require('needle'); | ||
var _ = require('lodash'); | ||
var Promise = require('bluebird'); | ||
Promise.promisifyAll(needle); | ||
var uuid = require('uuid'); | ||
var moment = require('moment'); | ||
var fs = require('fs'); | ||
|
||
var config = require('./config'); | ||
|
||
|
||
function fetchAttendance(params, cookies, modeReport, resBody) { | ||
|
||
var dataBuffer = []; | ||
var startIndex = 1; | ||
var ttl = 5; | ||
var requestToken = uuid.v1(); | ||
var attendanceURL = 'https://people.zoho.com/people/AttendanceReportAction.do'; | ||
|
||
var reqParams = _.extend({}, params, { | ||
mode: modeReport, | ||
conreqcsr: requestToken | ||
}); | ||
|
||
var options = { | ||
cookies: _.extend({}, cookies, {CSRF_TOKEN: requestToken}) | ||
}; | ||
|
||
var getNext = function () { | ||
|
||
return needle.postAsync(attendanceURL, reqParams, options) | ||
.then(function (res) { | ||
|
||
if (!res.body[resBody]) { | ||
throw new Error('Server returned something wrong: ' + JSON.stringify(res.body)); | ||
} | ||
|
||
dataBuffer = dataBuffer.concat(res.body[resBody]); | ||
|
||
var len = res.body[resBody].length; | ||
// Received all the data, return from the chain | ||
if (len < 50) { | ||
return dataBuffer; | ||
} | ||
|
||
ttl--; | ||
if (!ttl) { | ||
throw new Error('oops we have made too many requests, something is wrong'); | ||
} | ||
|
||
startIndex += 50; | ||
|
||
_.extend(reqParams, {startIndex: startIndex}); | ||
|
||
return Promise.delay(300).then(function () { | ||
return getNext(); | ||
}); | ||
}); | ||
}; | ||
|
||
return getNext(); | ||
} | ||
|
||
|
||
function logInToZoho(login, password) { | ||
|
||
var loginToken = uuid.v1(); | ||
|
||
var data = { | ||
LOGIN_ID: login, | ||
PASSWORD: password, | ||
IS_AJAX: 'true', | ||
remember: 2592000, | ||
iamcsrcoo: loginToken | ||
}; | ||
|
||
var loginURL = 'https://accounts.zoho.com/login?servicename=zohopeople'; | ||
|
||
return needle.postAsync(loginURL, data, { | ||
cookies: { | ||
iamcsr: loginToken | ||
} | ||
}); | ||
} | ||
|
||
|
||
function getDataFromZoho(date, modeReport, resBody) { | ||
|
||
var sdate = moment(date).subtract(1, 'day').startOf('month').format('DD-MMM-YYYY'); | ||
var edate = moment(date).subtract(1, 'day').endOf('month').format('DD-MMM-YYYY'); | ||
|
||
var cookies; | ||
|
||
return logInToZoho(config.login, config.password) | ||
.then(function (res) { | ||
|
||
cookies = res.cookies; | ||
|
||
return fetchAttendance({sdate: sdate, edate: edate}, cookies, modeReport, resBody) | ||
}) | ||
.then(function (data) { | ||
|
||
// logging out is a mandatory | ||
needle.getAsync('https://accounts.zoho.com/logout?serviceurl=https://www.zoho.com/people/zohopeople-logout.html', {cookies: cookies}); | ||
|
||
return data; | ||
}); | ||
} | ||
|
||
//=================================================== | ||
|
||
getDataFromZoho(new Date(), 'customReport', 'report') | ||
.then(function (data) { | ||
fs.writeFileSync('./data/' + moment(new Date()).subtract(1, 'day').format('YYYY-MM-DD') + '.json', JSON.stringify(data, 0, 2)); | ||
return fs.writeFileSync('./data/' + moment(new Date()).subtract(1, 'day').endOf('month').format('YYYY-MM') + '.json', JSON.stringify(data, 0, 2)); | ||
}) | ||
.catch(function (err) { | ||
console.error('FAIL. Something went terribly wrong.customReport'); | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
|
||
getDataFromZoho(new Date(), 'monthlyReport', 'dayList') | ||
.then(function (data) { | ||
return fs.writeFileSync('./data/' + moment(new Date()).subtract(1, 'day').endOf('month').format('YYYY-MM-')+ 'presence' + '.json', JSON.stringify(data, 0, 2)); | ||
}) | ||
.catch(function (err) { | ||
console.error('FAIL. Something went terribly wrong.monthlyReport'); | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "zoho-attendance-fetcher", | ||
"version": "1.0.0", | ||
"description": "Downloads Zoho People Attendance Reports", | ||
"main": "fetch-data.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Ivan Poddubny <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"bluebird": "^3.0.6", | ||
"lodash": "^3.10.1", | ||
"moment": "^2.10.6", | ||
"needle": "^0.11.0", | ||
"uuid": "^2.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# zpeople | ||
Zoho people | ||
Страница показа баланса времени пользователя по отчету из Zoho People https://www.zoho.com/people/ | ||
|
||
|
||
Требования использование подготовленного json файла находящегося в /zoho-data/ |
Oops, something went wrong.