Created
December 30, 2021 16:33
-
-
Save aikatsukamen/78a3a46af026c826da85960eec92fc56 to your computer and use it in GitHub Desktop.
showroom event ranking
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
| /** | |
| * SHOWROOMのポイントランキングを取得する | |
| */ | |
| const cheerio = libpack.cheerio(); | |
| // $ = cheerio.load(content); | |
| // イベントページのURL | |
| const url = 'https://www.showroom-live.com/event/ramen_mitani'; | |
| // 書き込むシート名。事前に作っておくこと。 | |
| const sheetName = 'まぜそば'; | |
| // writeHeaderで出力された参加者情報のJSON | |
| const streamers = [ | |
| { | |
| "name": "【ラーメン美谷ガチイベ】イヴとらいゔ♪", | |
| "id": "kinapro85", | |
| "roomId": "326084" | |
| }, | |
| { | |
| "name": "♡ガチイベ参加中!香澄まなのSHOWROOM♡", | |
| "id": "sendaiflavor_pink_BD", | |
| "roomId": "217603" | |
| }, | |
| { | |
| "name": "雷電為右衛門伝説:続", | |
| "id": "6b8ae5866825", | |
| "roomId": "380011" | |
| }, | |
| { | |
| "name": "【30日からまぜそばイベ】おちゃっぴーといっしょ!#OWTM", | |
| "id": "SSPYUKATA181", | |
| "roomId": "350704" | |
| } | |
| ]; | |
| /** ランキングにいるチャンネル名をヘッダー用に書き込み。最初に1回だけ実行。 */ | |
| function writeHeader(){ | |
| const res = UrlFetchApp.fetch(url, {muteHttpExceptions:true}); | |
| $ = cheerio.load(res.getContentText()); | |
| const result = []; | |
| $('.listcardinfo').each((index, value) => { | |
| // console.log(value); | |
| const name = $(value).find(".listcardinfo-main-text").text(); | |
| const id = $(value).find("a").attr("href").replace("/", ""); | |
| const roomId = $(value).find("a").attr("data-room-id"); | |
| result.push({ | |
| name: name, | |
| id: id, | |
| roomId: roomId | |
| }) | |
| }); | |
| console.log(JSON.stringify(result, null, ' ')); | |
| // シートに書き込み | |
| const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName); | |
| sheet.appendRow(["日時", ...result.map(item => item.name)]); | |
| } | |
| /** ポイントデータを取得する。これを定期実行。 */ | |
| function writeRanking() { | |
| const result = []; | |
| for(const streamer of streamers) { | |
| console.log(streamer.name); | |
| const url = `https://www.showroom-live.com/api/room/event_and_support?room_id=${streamer.roomId}`; | |
| const res = UrlFetchApp.fetch(url, {muteHttpExceptions:true}).getContentText(); | |
| const json = JSON.parse(res); | |
| const point = json.event.ranking.point; | |
| console.log(point); | |
| result.push(point); | |
| } | |
| // シートに書き込み | |
| const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName); | |
| const todayStr = createTodayStr(); | |
| sheet.appendRow([todayStr, ...result]); | |
| } | |
| function createTodayStr() { | |
| 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}`; | |
| return todayStr; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment