-
-
Save shikachii/76a368ee387281789874ff3750404824 to your computer and use it in GitHub Desktop.
arXivの最新論文を毎日slackに投稿するGoogle App 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
function postslack(entry) { | |
// WebHook | |
const url = 'https://hooks.slack.com/services/{YOUR_SECRET}'; | |
const content = { | |
'username': '{YOUR_NAME}', | |
'text': `<${entry.url}|${entry.title}>\n${entry.summary}`, | |
}; | |
const options = { | |
'method': 'post', | |
'content': 'applications/json', | |
'payload': JSON.stringify(content), | |
}; | |
UrlFetchApp.fetch(url, options); | |
} |
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 readrss() { | |
// 土日なら即終了 | |
const now = new Date(); | |
if (now.getDay() === 0 || now.getDay() === 6) return; | |
// CV分野の投稿順で最新3件を取得 | |
const url = 'http://export.arxiv.org/api/query?search_query=all:%22cs.CV%22&start=0&max_results=3&sortBy=submittedDate&sortOrder=descending'; | |
const xml = UrlFetchApp.fetch(url).getContentText(); | |
const xmlDocs = XmlService.parse(xml); | |
const namespace = XmlService.getNamespace('', 'http://www.w3.org/2005/Atom'); | |
const doc = xmlDocs.getRootElement().getChildren('entry', namespace); | |
const plain = (str) => { | |
return str.replace(/\r?\n/g, ''); | |
} | |
const entries = doc.forEach((d) => { | |
const enTitle = plain(d.getChild('title', namespace).getText()); | |
const enSummary = plain(d.getChild('summary', namespace).getText()); | |
const jaSummary = LanguageApp.translate(enSummary, 'en', 'ja'); | |
const url = d.getChild('id', namespace).getText(); | |
const entry = { | |
title: enTitle, | |
summary: jaSummary.replace(/。/g, '。\n'), | |
url, | |
}; | |
postslack(entry); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment