Created
January 30, 2020 11:19
-
-
Save haranicle/004cebd5c0c05da49eb4ca79d27e893f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 doGet(e) { | |
var vocabulary = e.parameter.v | |
var from = e.parameter.f | |
if (!vocabulary) { | |
return ContentService.createTextOutput("パラメータvが空だよ!"); | |
} | |
if (!from) { | |
return ContentService.createTextOutput("パラメータfが空だよ!"); | |
} | |
var id = '<1から始まるスプレッドシートのIDをここに入力>'; | |
var sheet = SpreadsheetApp.openById(id).getSheetByName("シート1"); | |
var weblio = "https://ejje.weblio.jp/content/" + encodeURI(vocabulary) | |
var regex = "^" + vocabulary + "$" | |
var finder = sheet.createTextFinder(regex).useRegularExpression(true); | |
if (finder.findNext() !== null) { | |
return ContentService.createTextOutput(weblio); | |
} | |
var translated = LanguageApp.translate(vocabulary, "en", "ja") | |
var date = Utilities.formatDate(new Date(), 'Asia/Tokyo', 'yyyy/MM/dd HH:mm:ss') | |
sheet.appendRow([vocabulary, translated, weblio, date, from]) | |
return ContentService.createTextOutput(weblio); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment