daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var competitionId = 534; // http://api.etf2l.org/competition/list
  2. var tier = 1 // 0 = prem, 1 = high etc
  3.  
  4. var app = SpreadsheetApp.getActiveSpreadsheet();
  5. var shLogs = app.getSheetByName('Logs');
  6.  
  7. function onOpen() {
  8.   app.getUi()
  9.     .createMenu('logs.tf Importer')
  10.       .addItem('Import Logs', 'importLogs')
  11.   .addToUi();
  12. }
  13.  
  14. function importLogs() {
  15.  
  16. }
  17.  
  18. function getMaxOfArray(numArray) {
  19.   return Math.max.apply(null, numArray);
  20. }
  21.  
  22. function createLogSpreadsheet() {
  23.   var jsonResultPages = ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results.json', '/page/total_pages', 'noHeaders')[0][0];
  24.   var jsonMatchPages = ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches.json', '/page/total_pages', 'noHeaders')[0][0];
  25.  
  26.   var clan1Id = [];
  27.   var clan1Name= [];
  28.   var clan2Id =[];
  29.   var clan2Name = [];
  30.   var skillLevel = [];
  31.   var week = [];
  32.   var map = [];
  33.  
  34.   for (var i = 1; i<=jsonResultPages; ++i) {
  35.     clan1Id = clan1Id.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/clan1/id', 'noHeaders'));
  36.     clan1Name = clan1Name.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/clan1/name', 'noHeaders'));
  37.     clan2Id = clan2Id.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/clan2/id', 'noHeaders'));
  38.     clan2Name = clan2Name.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/clan2/name', 'noHeaders'));
  39.     skillLevel = skillLevel.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/division/tier', 'noHeaders'));
  40.     week = week.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/week', 'noHeaders'));
  41.     map = map.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/maps', 'noHeaders'));
  42.   }
  43.  
  44.   for (var i = 1; i<=jsonMatchPages; ++i) {
  45.     clan1Id = clan1Id.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/clan1/id', 'noHeaders'));
  46.     clan1Name = clan1Name.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/clan1/name', 'noHeaders'));
  47.     clan2Id = clan2Id.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/clan2/id', 'noHeaders'));
  48.     clan2Name = clan2Name.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/clan2/name', 'noHeaders'));
  49.     skillLevel = skillLevel.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/division/tier', 'noHeaders'));
  50.     week = week.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/week', 'noHeaders'));
  51.     map = map.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/maps', 'noHeaders'));
  52.   }
  53.  
  54.   var numMatches = clan1Id.length;
  55.   var matches = [];
  56.  
  57.   for (var i = 0; i < numMatches; ++i) {
  58.     var match = {};
  59.     match["homeID"] = clan1Id[i];
  60.     match["homeName"] = clan1Name[i];
  61.     match["awayID"] = clan2Id[i];
  62.     match["awayName"] = clan2Name[i];
  63.     match["skillLevel"] = skillLevel[i];
  64.     match["week"] = week[i];
  65.     match["map"] = map[i];
  66.     matches.push(match);
  67.   }
  68.  
  69.   var weekNumber = getMaxOfArray(week);
  70.  
  71.   var tierMatches = matches.filter(function(match) {return match.skillLevel == tier;});
  72.   var weekMatches = [];
  73.  
  74.   shLogs.getRange(1,2).setValue('Home Link');
  75.   shLogs.getRange(1,3).setValue('Home Name');
  76.   shLogs.getRange(1,4).setValue('Away Link');
  77.   shLogs.getRange(1,5).setValue('Away Name');
  78.   shLogs.getRange(1,6).setValue('Map(s)');
  79.  
  80.   for (var w = 0; w < weekNumber; w++) {
  81.     weekMatches[w] = tierMatches.filter(function(match) {return match.week == (+w + +1);});
  82.   }
  83.  
  84.   var row = 1;
  85.   for (var w = 0; w < 5; w++) {
  86.  
  87.     shLogs.getRange(row,1).setValue('Week ' + (+w + +1)); //set week title
  88.    
  89.     row += 1;
  90.     for (i = 0; i < weekMatches[w].length; i++, row++) {
  91.       shLogs.getRange(row,2).setValue("http://etf2l.org/teams/" + weekMatches[w][i].homeID);
  92.       shLogs.getRange(row,3).setValue(weekMatches[w][i].homeName);
  93.       shLogs.getRange(row,4).setValue("http://etf2l.org/teams/" + weekMatches[w][i].awayID);
  94.       shLogs.getRange(row,5).setValue(weekMatches[w][i].awayName);
  95.       shLogs.getRange(row,6).setValue(weekMatches[w][i].map);
  96.     }
  97.   }
  98.  
  99. }
RAW Paste Data
Top