Created
March 30, 2020 12:51
-
-
Save discoNeko/456b48b4d5efff6bac9918fab8fe2562 to your computer and use it in GitHub Desktop.
M&A案件一覧を取得してslack通知、最新のものだけスプレッドシートに保存
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
function get(){ | |
const response = UrlFetchApp.fetch("https://www.tranbi.com/buy/list/?prill=&priul=2500000&srl=&sru=&proll=&proul=&sd=1&sin=1&ft=&sort=-open_datetime&page_size=30"); | |
const entries = Parser.data(response.getContentText()).from('<div class="buyListContents">').to('<div class="buyListBtn">').iterate(); | |
const sheet = SpreadsheetApp.getActiveSheet(); | |
const range = sheet.getRange('A2'); | |
const currentID = range.getValue(); | |
const newEntries = [] | |
entries.some(entry => { | |
const newEntry = [] | |
const id = Parser.data(entry).from('<p>ID:').to(' ').build().trim(); | |
// 前回取得した最新の案件にヒットしたら処理終了 | |
if(id == currentID) return true; | |
newEntry.push(id); | |
const date = Parser.data(entry).from('公開日:').to(' ').build().trim(); | |
newEntry.push(date); | |
const title = Parser.data(entry).from('</span>').to('</h2>').build().trim(); | |
newEntry.push(title); | |
const category = Parser.data(entry).from('<span class="categoryTag">').to('</span>').build().trim(); | |
newEntry.push(category); | |
const price = Parser.data(entry).from('<td>').to('</td>').iterate(); | |
const sales = price[0]; | |
const income = price[1]; | |
const suggested = price[2]; | |
newEntry.push(sales); | |
newEntry.push(income); | |
newEntry.push(suggested); | |
newEntries.push(newEntry); | |
}) | |
// 新規案件が無ければ終了 | |
if(newEntries.length == 0) return 0; | |
const rows = newEntries.length; | |
const cols = newEntries[0].length; | |
sheet.insertRows(2, rows); | |
sheet.getRange(2, 1, rows, cols).setValues(newEntries); | |
sendSlack(newEntries); | |
} | |
const postUrl = 'your slack webhook url'; | |
function sendSlack(newEntries) { | |
// 送信テキスト | |
const payload = { | |
'blocks': [ | |
{ | |
'type': 'section', | |
'text': { | |
'type': 'mrkdwn', | |
'text': '*【M&A速報】* <https://www.tranbi.com/buy/list/?prill=&priul=2500000&srl=&sru=&proll=&proul=&sd=1&sin=1&ft=&sort=-open_datetime&page_size=30|TRANBI> \n' | |
} | |
} | |
] | |
}; | |
newEntries.forEach(entry => { | |
const [, , title, category, sales, income, suggested] = entry; | |
// 送信メッセージ | |
payload.blocks.push( | |
{ | |
'type': 'divider' | |
}, | |
{ | |
'type': 'section', | |
'text': { | |
'type': 'mrkdwn', | |
'text': '*' + title + '* \nカテゴリ:' + category + '\n売上高:' + sales + '\n営業利益:' + income + '\n売却希望額:' + suggested | |
} | |
}) | |
}); | |
const options = | |
{ | |
"method" : "post", | |
"contentType" : "application/json", | |
"payload" : JSON.stringify(payload) | |
}; | |
UrlFetchApp.fetch(postUrl, options); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment