Skip to content

Instantly share code, notes, and snippets.

@yarnaimo
Created March 25, 2019 07:04
Show Gist options
  • Save yarnaimo/7be5bd1eac28f5b8dca5bb508e95d741 to your computer and use it in GitHub Desktop.
Save yarnaimo/7be5bd1eac28f5b8dca5bb508e95d741 to your computer and use it in GitHub Desktop.
Eventernoteの新規イベントをIFTTTのWebhooksに投げるスクリプト (Google Apps Script)
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