Created
April 19, 2018 09:00
-
-
Save FeraruSilviuMarian/6e70c48cab28fee78a74754df1398bc3 to your computer and use it in GitHub Desktop.
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
/** | |
* @OnlyCurrentDoc | |
*/ | |
// this script is intended for the google apps script for google spreadsheets, tools>script editor, copy paste the code after you make | |
// the propper adjustments, such as getting an api key and inserting your username, see details at https://fortnite.y3n.co/ | |
var triggerColumn = 2; | |
var triggerRow = 3; | |
var timestampColumn = 'I'; | |
var username = 'your fortnite username goes here'; | |
var sheetMode = 'solo'; // available modes: 'solo', 'duo', 'all' or 'squads' | |
// get an api key by direct messaging @Fortnite Stats on discord, with the message !getapikey visit https://fortnite.y3n.co/ for more details | |
var key = 'your api key goes here'; | |
// in order for this function to populate a row with stats every 12 hours, make a trigger for it from the script editor | |
function populate(){ | |
// current row to populate | |
var crow = SpreadsheetApp.getActiveSheet().getRange('H' + '3').getValue(); | |
// get response from server | |
var url = "https://fortnite.y3n.co/v2/player/" + username; | |
var options = { | |
'headers': {'X-Key': key} | |
}; | |
var response = UrlFetchApp.fetch(url, options); | |
var text = response.getContentText(); | |
var json = JSON.parse(text); | |
// populate spreadsheet with the right stats | |
if(sheetMode == 'solo'){ | |
soloStats(crow, json); | |
} | |
else if(sheetMode == 'duo'){ | |
duoStats(crow, json); | |
} | |
else if(sheetMode == 'squad'){ | |
squadStats(crow, json); | |
} | |
else if(sheetMode == 'all'){ | |
allStats(crow, json); | |
} | |
// call timestamp on current row | |
timeStamp(crow); | |
// increment current row to prepare for next call | |
var temp = parseInt(crow) + 1; | |
var set = temp.toString(); | |
SpreadsheetApp.getActiveSheet().getRange('H' + '3').setValue(set); | |
} | |
function soloStats(crow, json){ | |
// prepare data | |
var wins = json.br.stats.pc.solo.wins | |
var winrate = json.br.stats.pc.solo.winRate | |
var kills = json.br.stats.pc.solo.kills | |
var matches = json.br.stats.pc.solo.matchesPlayed | |
var kpd = json.br.stats.pc.solo.kpd | |
// populate spreadsheet with solo stats | |
SpreadsheetApp.getActiveSheet().getRange('B' + crow).setValue(crow - 4); | |
SpreadsheetApp.getActiveSheet().getRange('C' + crow).setValue(wins); | |
SpreadsheetApp.getActiveSheet().getRange('D' + crow).setValue(winrate); | |
SpreadsheetApp.getActiveSheet().getRange('E' + crow).setValue(kills); | |
SpreadsheetApp.getActiveSheet().getRange('F' + crow).setValue(matches); | |
SpreadsheetApp.getActiveSheet().getRange('G' + crow).setValue(kpd); | |
} | |
function duoStats(crow, json){ | |
// prepare data | |
var wins = json.br.stats.pc.duo.wins | |
var winrate = json.br.stats.pc.duo.winRate | |
var kills = json.br.stats.pc.duo.kills | |
var matches = json.br.stats.pc.duo.matchesPlayed | |
var kpd = json.br.stats.pc.duo.kpd | |
// populate spreadsheet with duo stats | |
SpreadsheetApp.getActiveSheet().getRange('B' + crow).setValue(crow - 4); | |
SpreadsheetApp.getActiveSheet().getRange('C' + crow).setValue(wins); | |
SpreadsheetApp.getActiveSheet().getRange('D' + crow).setValue(winrate); | |
SpreadsheetApp.getActiveSheet().getRange('E' + crow).setValue(kills); | |
SpreadsheetApp.getActiveSheet().getRange('F' + crow).setValue(matches); | |
SpreadsheetApp.getActiveSheet().getRange('G' + crow).setValue(kpd); | |
} | |
function squadStats(crow, json){ | |
// prepare data | |
var wins = json.br.stats.pc.squad.wins | |
var winrate = json.br.stats.pc.squad.winRate | |
var kills = json.br.stats.pc.squad.kills | |
var matches = json.br.stats.pc.squad.matchesPlayed | |
var kpd = json.br.stats.pc.squad.kpd | |
// populate spreadsheet with squad stats | |
SpreadsheetApp.getActiveSheet().getRange('B' + crow).setValue(crow - 4); | |
SpreadsheetApp.getActiveSheet().getRange('C' + crow).setValue(wins); | |
SpreadsheetApp.getActiveSheet().getRange('D' + crow).setValue(winrate); | |
SpreadsheetApp.getActiveSheet().getRange('E' + crow).setValue(kills); | |
SpreadsheetApp.getActiveSheet().getRange('F' + crow).setValue(matches); | |
SpreadsheetApp.getActiveSheet().getRange('G' + crow).setValue(kpd); | |
} | |
function allStats(crow, json){ | |
// prepare data | |
var wins = json.br.stats.pc.all.wins | |
var winrate = json.br.stats.pc.all.winRate | |
var kills = json.br.stats.pc.all.kills | |
var matches = json.br.stats.pc.all.matchesPlayed | |
var kpd = json.br.stats.pc.all.kpd | |
// populate spreadsheet with all stats | |
SpreadsheetApp.getActiveSheet().getRange('B' + crow).setValue(crow - 4); | |
SpreadsheetApp.getActiveSheet().getRange('C' + crow).setValue(wins); | |
SpreadsheetApp.getActiveSheet().getRange('D' + crow).setValue(winrate); | |
SpreadsheetApp.getActiveSheet().getRange('E' + crow).setValue(kills); | |
SpreadsheetApp.getActiveSheet().getRange('F' + crow).setValue(matches); | |
SpreadsheetApp.getActiveSheet().getRange('G' + crow).setValue(kpd); | |
} | |
function timeStamp(crow){ | |
var date = Utilities.formatDate(new Date(), "GMT+2", "dd/MM/yyyy"); // formated date | |
SpreadsheetApp.getActiveSheet().getRange(timestampColumn + crow).setValue(date); // Set the value of a cell to a date. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment