Skip to content

Instantly share code, notes, and snippets.

@aikatsukamen
Last active August 22, 2021 23:40
Show Gist options
  • Select an option

  • Save aikatsukamen/6096875773fdff3c341b29b19a0c1366 to your computer and use it in GitHub Desktop.

Select an option

Save aikatsukamen/6096875773fdff3c341b29b19a0c1366 to your computer and use it in GitHub Desktop.
LINE LIVEデータ取得
/**
* LINE LIVEのポイントランキングを取得する
*/
// APIのURL。イベントページの番号だけ差し替えればOK
const url = 'https://live-api.line-apps.com/web/v3.7/events/10111/ranking';
// 書き込むシート名。事前に作っておくこと。
const sheetName = '決勝';
/** ランキングにいるチャンネル名をヘッダー用に書き込み。最初に1回だけ実行。 */
function writeHeader(){
const res = UrlFetchApp.fetch(url, {muteHttpExceptions:true});
const json = JSON.parse(res.getContentText());
if(!json.rows) throw new Error('イベントが開催されていません ' + JSON.stringify(json));
const result = json.rows.sort((a, b) => {
if(a.channelId > b.channelId) return 1;
if(a.channelId < b.channelId) return -1;
return 0;
}).map((item)=> {
return item.channelName;
});
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
sheet.appendRow(["日時", ...result]);
}
/** ポイントデータを取得する。これを定期実行。 */
function writeRanking() {
const res = UrlFetchApp.fetch(url, {muteHttpExceptions:true});
const json = JSON.parse(res.getContentText());
if(!json.rows) throw new Error('イベントが開催されていません ' + JSON.stringify(json));
const list = json.rows.sort((a, b) => {
if(a.channelId > b.channelId) return 1;
if(a.channelId < b.channelId) return -1;
return 0;
});
console.log(list.map(item => item.channelId));
const result = list.map((item)=> {
return item.point;
});
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
const today = new Date();
const year = `${today.getFullYear()}`;
const month = `0${today.getMonth()+1}`.slice(-2);
const day = `0${today.getDate()}`.slice(-2);
const hour = `0${today.getHours()}`.slice(-2);
const min = `0${today.getMinutes()}`.slice(-2);
const sec = `0${today.getSeconds()}`.slice(-2);
const todayStr = `${year}/${month}/${day} ${hour}:${min}:${sec}`;
sheet.appendRow([todayStr, ...result]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment