-
Notifications
You must be signed in to change notification settings - Fork 1
番組表
Tatsuya Koishi edited this page Nov 15, 2021
·
22 revisions
キュアスタ!の独自改造「実況用タグ」には、番組表のJSONを返すAPIが必要。
- 以下の様なGoogleスプレッドシートによる番組表を、毎朝(あるいは随時)更新する運用。
- スプレッドシート例
- 上記のスプレッドシートは、JSONに変換される。
- API例
- 以下、このAPIのApps Scriptによるソース。(Chrome V8エンジンを使用)
'use strict'
function doGet(e) {
const sheet = SpreadsheetApp.getActiveSpreadsheet()
const rows = sheet.getDataRange().getValues()
const keys = rows.splice(0, 1)[0]
const output = {}
rows.map(row => {
const item = {}
row.map((val, i) => {item[keys[i]] = val})
item.air = (item.air == 1)
item.enable = (item.enable == 1)
item.episode = item.episode ? parseInt(item.episode) : null
item.extra_tags = item.extra_tags ? item.extra_tags.split(',') : []
output[item.key] = item
})
return ContentService.createTextOutput(JSON.stringify(output)).setMimeType(ContentService.MimeType.JSON)
}
/program/urls を設定する。
Google Apps Scriptは高速に実行出来ないケースがあり、取得した結果をキャッシュしなければ安定しない。
/program/urlsで指定したURLの内容はキャッシュされ、同じ内容が公開API GET /mulukhiya/api/programs
からも配信される。
program:
urls:
- https://script.google.com/macros/s/AKfycbxlqRJxUq1dIsshRF6luZvL-_T08OTZD7YKOmAhLHfZeoZy3Ox-/exec