トライオートfxの約定メールをLINEに送る
トライオートfxの仕様の変更
Google Apps Script
LINE Notify
ラベルを作る
コピペ
function main() {
const sheet = SpreadsheetApp.getActiveSheet();
const query = 'label:【トライオートFX】 is:unread';
const threads = GmailApp.search(query);
const messages = GmailApp.getMessagesForThreads(threads)
.reduce(function (a, c) {
const unreads = c.filter(function(m){ return m.isUnread(); });
unreads.forEach(function(m) { m.markRead(); });
return a.concat(unreads.map(messageToArray));
}, []);
if(messages.length < 1) { return; }
sheet.getRange(sheet.getLastRow() + 1, 1, messages.length, 6).setValues(messages);
sendLineNotify(valMsgs);
}
function messageToArray(mail) {
var new_close = mail.getPlainBody().match(/\[新規決済\]\s\s.*/)[0].slice(-2);
var ver_no = mail.getPlainBody().match(/ver.*/)[0].slice(-30).replace(/ver/, "");
var close_time = mail.getPlainBody().match(/\[約定成立日時\]\s\s.*/)[0].slice(-30).replace(/\[約定成立日時\]\s\s/, "");
var currency = mail.getPlainBody().match(/\[商品\]\s\s.*/)[0].slice(-20).replace(/\[商品\]\s\s/, "");
var sell_buy = mail.getPlainBody().match(/\[売買\]\s\s.*/)[0].slice(-1);
if(new_close.indexOf('決済') > -1){
var profit_price = mail.getPlainBody().match(/\[損益\]\s\s.*/)[0].slice(-20).replace(/\[損益\]\s\s/, "")
var profit_price = profit_price.replace(/円/, "")
}else{
var profit_price = mail.getPlainBody().match(/\[約定価格\]\s\s.*/)[0].slice(-20).replace(/\[約定価格\]\s\s/, "")
//var profit_price = 0
}
valMsgs =
close_time
+ "\n" + currency
+ " ver" + ver_no
+ sell_buy
+ " " + new_close
+ " " + profit_price;
var body = mail.getBody().slice(70,200)
return [mail.getId(), close_time, currency, "ver" + ver_no, sell_buy, profit_price];
}
function sendLineNotify(message){
var token = 'X XXXXXXXXXXXXXXXXXXXXXXXXXXX';
var options =
{
'method' : 'post',
'payload' : 'message=' + message,
'headers' : {'Authorization' : 'Bearer '+ token}
};
UrlFetchApp.fetch('https://notify-api.line.me/api/notify',options);
}
この記事が気に入ったらサポートをしてみませんか?