Created
March 25, 2019 07:04
-
-
Save yarnaimo/7be5bd1eac28f5b8dca5bb508e95d741 to your computer and use it in GitHub Desktop.
Eventernoteの新規イベントをIFTTTのWebhooksに投げるスクリプト (Google Apps Script)
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 eventListUrl = 'https://www.eventernote.com/actors/xxx/xxx' | |
var webhookUrl = 'http://maker.ifttt.com/trigger/xxx/with/key/xxx' | |
var s = SpreadsheetApp.getActiveSheet() | |
function getIdsInSheet() { | |
return s | |
.getDataRange() | |
.getValues() | |
.map(function (row) { return String(row[0]) }) | |
} | |
function saveIdToSheet(id) { | |
s.appendRow([id]) | |
} | |
function hook(id) { | |
var value1 = 'https://www.eventernote.com/events/' + id | |
UrlFetchApp.fetch(webhookUrl, { | |
method: 'post', | |
payload: { value1: value1 }, | |
}) | |
} | |
function testHook() { | |
hook('193475') | |
} | |
function main() { | |
var idsInSheet = getIdsInSheet() | |
var response = UrlFetchApp.fetch(eventListUrl) | |
var html = response.getContentText() | |
var matches = html.match(/<a [^>]*?href="\/events\/\d+"/g) | |
var idsInPage = matches.map(function (m) { return m.match(/(\d+)"$/)[1] }) | |
var newIds = idsInPage.filter(function (id) { return idsInSheet.indexOf(id) === -1 }) | |
newIds.forEach(hook) | |
newIds.forEach(saveIdToSheet) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment