-
-
Save aikatsukamen/6096875773fdff3c341b29b19a0c1366 to your computer and use it in GitHub Desktop.
LINE LIVEデータ取得
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
| /** | |
| * 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