Last active
December 22, 2018 04:29
-
-
Save maruhoi1/4801939e9aec5cc796fb3e6b47d73f8d to your computer and use it in GitHub Desktop.
Google Apps Scripts for Steam Status Crawler
This file contains 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
function setActivity() { | |
//記録用スプレッドシートを取得 | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
//Steamプロフィールページのリンク | |
var url = "https://steamcommunity.com/id/maruhoi1"; | |
//プロフィールページを取得する | |
var content = UrlFetchApp.fetch(url).getContentText(); | |
//ゲーム中かゲーム中ではないかを判断するためのパース用変数 | |
var fromText = '<div class="profile_in_game persona '; | |
var toText = '">'; | |
//ゲーム中でなければ「ゲームしてません」と記録して、ゲーム中であればタイトル名を記録する | |
if(startParse(content,fromText,toText) !== "in-game"){ | |
sheet.getRange(sheet.getLastRow()+1,1,1,2).setValues([[getDate(),"ゲームしてません"]]); | |
}else{ | |
var fromText = '<div class="profile_in_game_name">'; | |
var toText = '</div>'; | |
sheet.getRange(sheet.getLastRow()+1,1,1,2).setValues([[getDate(),startParse(content,fromText,toText)]]); | |
} | |
} | |
//外部ライブラリで引数を利用してパースする関数 | |
function startParse(content,fromText,toText){ | |
return Parser.data(content).from(fromText).to(toText).build(); | |
} | |
//コード実行した日時を取得する関数 | |
function getDate(){ | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var date = new Date(); | |
return Utilities.formatDate(date,"JST","yyyy/MM/dd HH:mm"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment