Last active
February 16, 2017 00:32
-
-
Save 4noha/b04c399a83437b714e0f280fb30e6416 to your computer and use it in GitHub Desktop.
node.jsでDashボタンによってアレしてPush Bulletに結果投げるやつ
This file contains hidden or 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
const DashButton = require( 'dash-button' ); | |
const Request = require( 'request' ); | |
const Fs = require( 'fs' ); | |
const Iconv = require( 'iconv-lite' ); | |
const PushBullet = require( 'pushbullet' ); | |
const D_BUTTON_MAC = 'xx:xx:xx:xx:xx:xx'; | |
const EMPLOYEE_NO = 'にゃ〜ん'; | |
const PASSWORD = 'にゃ〜ん'; | |
const PUSH_ACCOUNT = 'にゃ〜ん'; | |
const PUSH_TOKEN = 'にゃ〜ん'; | |
const Pusher = new PushBullet( PUSH_TOKEN ); | |
let button = new DashButton( D_BUTTON_MAC ); | |
let subscription = button.addListener( () => { | |
var cTime = new Date(); | |
var options; | |
// 時間で出退勤制御(タイムゾーンに注意) | |
if (cTime.getHours() < 17) { | |
options = { | |
url: 'https://cws.にゃ〜ん.jp/cws30/srwtimerec?dakoku=syussya&user_id=' + EMPLOYEE_NO + '&password=' + PASSWORD, | |
encoding: 'binary', | |
}; | |
} else { | |
options = { | |
url: 'https://cws.にゃ〜ん.jp/cws30/srwtimerec?dakoku=taisya&user_id=' + EMPLOYEE_NO + '&password=' + PASSWORD, | |
encoding: 'binary', | |
}; | |
} | |
Request.get(options, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
var buf = new Buffer(body, 'binary'); | |
var retStr = Iconv.decode(buf, "Shift_JIS"); | |
var reMorning = /今日も一日がんばりましょう!/; | |
var reNight = /お疲れ様でした。/; | |
var reTimeSplitter = /<u> | <\/u>/; | |
var recTime = retStr.split( reTimeSplitter )[1]; | |
// テキストで出退勤判定 | |
if ( reMorning.test( retStr ) ){ | |
Pusher.note( PUSH_ACCOUNT, '出勤', recTime, function( error, response ) {} ); | |
console.log( 'in:' + recTime ); | |
return; | |
} else if ( reNight.test( retStr ) ) { | |
Pusher.note( PUSH_ACCOUNT, '退勤', recTime, function( error, response ) {} ); | |
console.log( 'out:' + recTime ); | |
return; | |
} | |
} | |
Pusher.note( PUSH_ACCOUNT, '勤怠エラー', 'error', function( error, response ) {} ); | |
console.log( 'error: ' + response.statusCode ); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment