Created
May 18, 2021 16:11
-
-
Save niwatako/634f2ef0c8c4de66182d14de79069de8 to your computer and use it in GitHub Desktop.
金融庁の暗号資産交換業者一覧のPDFが更新されていないか確認し、更新されていれば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
var SLACK_USER_ID_TO_NOTICE = PropertiesService.getScriptProperties().getProperty("SLACK_USER_ID_TO_NOTICE") | |
var SLACK_WEBHOOK_URL = PropertiesService.getScriptProperties().getProperty("SLACK_WEBHOOK_URL") | |
var SLACK_CHANNEL = PropertiesService.getScriptProperties().getProperty("SLACK_CHANNEL") | |
var SLACK_BOT_NAME = PropertiesService.getScriptProperties().getProperty("SLACK_BOT_NAME") | |
var DIGEST_PROPERTY_KEY = "DIGEST_PROPERTY_KEY" | |
function main() { | |
var url = "https://www.fsa.go.jp/menkyo/menkyoj/kasoutuka.pdf" | |
var pdf = UrlFetchApp.fetch(url).getAs('application/pdf') | |
var bytes = pdf.getBytes | |
var digest = MD5_(bytes) | |
var scriptProperties = PropertiesService.getScriptProperties(); | |
var previous_digest = scriptProperties.getProperty(DIGEST_PROPERTY_KEY) | |
if (digest == previous_digest) { | |
return | |
} else { | |
scriptProperties.setProperty(DIGEST_PROPERTY_KEY, digest) | |
sendToSlack_(SLACK_USER_ID_TO_NOTICE + "金融庁 暗号資産交換業者登録一覧 が更新されました\n" + url); | |
return | |
} | |
} | |
function MD5_ (input) { | |
var rawHash = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, input, Utilities.Charset.UTF_8); | |
var txtHash = ''; | |
for (i = 0; i < rawHash.length; i++) { | |
var hashVal = rawHash[i]; | |
if (hashVal < 0) { | |
hashVal += 256; | |
} | |
if (hashVal.toString(16).length == 1) { | |
txtHash += '0'; | |
} | |
txtHash += hashVal.toString(16); | |
} | |
return txtHash; | |
} | |
function sendToSlack_(message) { | |
var url = SLACK_WEBHOOK_URL; | |
var data = { | |
"channel" : SLACK_CHANNEL, | |
"username" : SLACK_BOT_NAME, | |
"text" : message, | |
//"unfurl_links": true, | |
}; | |
var payload = JSON.stringify(data); | |
var options = { | |
"method" : "POST", | |
"contentType" : "application/json", | |
"payload" : payload | |
}; | |
return UrlFetchApp.fetch(url, options); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment