Skip to content

Instantly share code, notes, and snippets.

@haranicle
Created January 30, 2020 11:19
Show Gist options
  • Save haranicle/004cebd5c0c05da49eb4ca79d27e893f to your computer and use it in GitHub Desktop.
Save haranicle/004cebd5c0c05da49eb4ca79d27e893f to your computer and use it in GitHub Desktop.
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