Skip to content

Instantly share code, notes, and snippets.

@4noha
Created March 20, 2017 14:14
Show Gist options
  • Save 4noha/4ee77b6bbc90d346d8b905fce3fa6c06 to your computer and use it in GitHub Desktop.
Save 4noha/4ee77b6bbc90d346d8b905fce3fa6c06 to your computer and use it in GitHub Desktop.
const DashButton = require( 'dash-button' );
const Request = require( 'request' );
const D_BUTTON_MAC = 'xx:xx:xx:xx:xx:xx';
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