Last active
August 6, 2017 09:48
-
-
Save zwrawr/956cc7cbac50b2856ce4b2828fc6d428 to your computer and use it in GitHub Desktop.
Scraper for ludumdare's stat api. Powers https://docs.google.com/spreadsheets/d/1pSJKbOCHCM_1kau6w4u4mieggZeAHSIyQ26W71jLdj4
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
// Scraper for ludumdare's stat api. | |
// Powers https://docs.google.com/spreadsheets/d/1pSJKbOCHCM_1kau6w4u4mieggZeAHSIyQ26W71jLdj4 | |
function getJSON() { | |
var sheetname = "stats"; | |
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetname); | |
var row1 = sheet.getRange("A1:AC1") | |
var headers = row1.getValues()[0]; | |
var Url = "https://api.ldjam.com/vx/stats/9405?pretty"; | |
var response = UrlFetchApp.fetch(Url); // get feed | |
var dataAll = JSON.parse(response.getContentText()); | |
var stats = dataAll.stats; | |
stats["event-id"] = dataAll["id"]; | |
stats["time"] = convertDate(stats["timestamp"]); | |
stats["grade-1-5"] = stats["grade-0-5"]-stats["grade-0-only"]; | |
stats["ranked"] = stats["grade-20-plus"]; | |
stats["unranked"] = stats["game"]-stats["ranked"]; | |
stats["ranked-percentage"] = stats["ranked"]/stats["game"]; | |
stats["unranked-percentage"] = stats["unranked"]/stats["game"]; | |
var values = []; | |
for (var i=0; i<headers.length; i++) { | |
values.push(stats[headers[i]]); | |
} | |
sheet.appendRow(values); | |
} | |
function convertDate(rawDate){ | |
var d = Moment.moment(rawDate).toDate(); | |
return d; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment