BLOGサブスレッドの日常
2016.06.30
当日の作業日報を便利に書く
torikai
遅れましてすみません。
水曜日担当の秋山です。よろしくお願いします。
今週の「社内「今何してる掲示板(仮)」をつくる」はお休みです。すみません(´・ω・`)
今日のひとネタ
「今何してる掲示板(仮)」が無いので、今はチャットで「今何してる」を書いています。
このチャットログを読み込んで、日報のたたき台を生成してくれる、便利なスクリプトを nodejs
で書きました。
自分用なのでかなりザルい処理なんですが、スクリプトはこんな感じです。
var request = require('request');
var room_id = '[今何してるのルームID]';
var my_room_id = '[マイチャットID]';
var my_account_id = '[自分のアカウントID]';
var chatworktoken = '[チャットワークのAPIトークン]';
var options = {
url: 'https://api.chatwork.com/v1/rooms/'+room_id+'/messages?force=1',
headers: {
'X-ChatWorkToken': chatworktoken
},
json: true
};
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position){
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(searchString, position) {
var subjectString = this.toString();
if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
position = subjectString.length;
}
position -= searchString.length;
var lastIndex = subjectString.indexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position;
};
}
function post_message(message, _post){
options.url = 'https://api.chatwork.com/v1/rooms/'+my_room_id+'/messages';
options.form = { body: message };
request.post(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
_post(body);
}else{
console.log('error: '+ response.statusCode);
_post(false);
}
});
}
request.get(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
var t = new Date();
var today = new Date([t.getFullYear(), ('0'+(t.getMonth()+1)).slice(-2), ('0'+t.getDate()).slice(-2)].join('/'));
var filtered = body
.filter(function(e, i, array){ return e.account.account_id == my_account_id })
.filter(function(e, i, array){ return (!e.body.startsWith('https://') && e.body.split('\n')[1] != '完了'); })
.filter(function(e, i, array){ return new Date(e.send_time * 1000) > today; });
var records = {};
filtered.forEach(function(v) {
var s = new Date(v.send_time * 1000)
var b = v.body.split('\n');
var body = b
.filter(function(e, i, array){ return !(e.startsWith('話しかけ') || e.endsWith('ぐらいまで')); }).join('\n')
.split('\n');
var gyoumu = body[0];
var work = body[1] || '';
if (!(gyoumu in records)) {
records[gyoumu] = [];
}
if (work) {
records[gyoumu].push(work);
}
});
var messages = [];
messages.push('《本日の作業内容》')
for(gyoumu in records) {
messages.push('* ' + gyoumu);
records[gyoumu].forEach(function(v){
messages.push(' * ' + v);
});
}
messages.push('《明日の作業予定》');
post_message(messages.join('\n'), function(data) {
console.log(data)
});
}else{
console.log('error: '+ response.statusCode);
}
});
「今何してる」のチャットに、こんな感じで書いておいて
サブスレッド
12:00 ぐらいまで
ブログを書く
話しかけ:OK
で、これを node report.js
みたく実行すると、マイチャットに
《本日の作業内容》
* A案件
* 動作確認
* 修正対応
* 履歴ログテスト
* 終了時間未定
* B案件
* 工数見積り
* まだだった
* C案件
* D案件
* 資料確認してました
《明日の作業予定》
と、実行した当日のログを整形して出してくれます。
処理と、そもそもの投稿フォーマットがザルいので、変な結果も出たりとかします…
内容を確認して、手直しして、作業報告として社内に共有。
なんとお手軽。マーベラス(*´ω`*)
というか早く作らないとですね… がんばります><;
ではまた来週にー。
この記事を書いた人
torikai