function importCSVhighscore() { var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Character Stats"); var cell = ss.getRange("Character Stats!B2"); var cellValue = cell.getValue(); var rsurl = "http://services.runescape.com/m=hiscore/index_lite.ws?player="; // new link //var rsurl = "http://hiscore.runescape.com/index_lite.ws?player="; // old link var csvUrl = rsurl+cellValue; var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CSVStats"); var range = sheet.getRange("A1:C61"); range.clearContent(); var csvContent = UrlFetchApp.fetch(csvUrl).getContentText(); var csvData = Utilities.parseCsv(csvContent); var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CSVStats"); sheet.getRange(2, 2, csvData.length, csvData[0].length).setValues(csvData); setHeaders(); importQuests(); } function importQuests() { var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Character Stats"); var cell = ss.getRange("Character Stats!B2"); var cellValue = cell.getValue(); var rsurl = "https://apps.runescape.com/runemetrics/quests?user="; // new link var jsonUrl = rsurl+cellValue; var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("QuestApi"); var range = sheet.getRange("A:E"); range.clearContent(); sheet.getRange(1, 1).setValue("Title") sheet.getRange(1, 2).setValue("Status") sheet.getRange(1, 3).setValue("Difficulty"); sheet.getRange(1, 4).setValue("Quest Points") sheet.getRange(1, 5).setValue("User Eligible") var csvContent = JSON.parse(UrlFetchApp.fetch(jsonUrl).getContentText()); for (var i = 0; i < csvContent["quests"].length; ++i) { sheet.getRange(i + 2, 1).setValue(csvContent["quests"][i]["title"]) sheet.getRange(i + 2, 2).setValue(csvContent["quests"][i]["status"]) switch(csvContent["quests"][i]["difficulty"]) { case 0: sheet.getRange(i + 2, 3).setValue("Novice"); break; case 1: sheet.getRange(i + 2, 3).setValue("Intermediate"); break; case 2: sheet.getRange(i + 2, 3).setValue("Experienced"); break; case 3: sheet.getRange(i + 2, 3).setValue("Master"); break; case 4: sheet.getRange(i + 2, 3).setValue("Grandmaster"); break; default: sheet.getRange(i + 2, 3).setValue("Special"); break; } sheet.getRange(i + 2, 4).setValue(csvContent["quests"][i]["questPoints"]) sheet.getRange(i + 2, 5).setValue(csvContent["quests"][i]["userEligible"]) } } function setHeaders() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CSVStats"); sheet.getRange(1, 2).setValue("Rank"); sheet.getRange(1, 3).setValue("Level"); sheet.getRange(1, 4).setValue("Experience"); sheet.getRange(2, 1).setValue("Overall"); sheet.getRange(3, 1).setValue("Attack"); sheet.getRange(4, 1).setValue("Defence"); sheet.getRange(5, 1).setValue("Strength"); sheet.getRange(6, 1).setValue("Constitution"); sheet.getRange(7, 1).setValue("Ranged"); sheet.getRange(8, 1).setValue("Prayer"); sheet.getRange(9, 1).setValue("Magic"); sheet.getRange(10, 1).setValue("Cooking"); sheet.getRange(11, 1).setValue("Woodcutting"); sheet.getRange(12, 1).setValue("Fletching"); sheet.getRange(13, 1).setValue("Fishing"); sheet.getRange(14, 1).setValue("Firemaking"); sheet.getRange(15, 1).setValue("Crafting"); sheet.getRange(16, 1).setValue("Smithing"); sheet.getRange(17, 1).setValue("Mining"); sheet.getRange(18, 1).setValue("Herblore"); sheet.getRange(19, 1).setValue("Agility"); sheet.getRange(20, 1).setValue("Thieving"); sheet.getRange(21, 1).setValue("Slayer"); sheet.getRange(22, 1).setValue("Farming"); sheet.getRange(23, 1).setValue("Runecrafting"); sheet.getRange(24, 1).setValue("Hunter"); sheet.getRange(25, 1).setValue("Construction"); sheet.getRange(26, 1).setValue("Summoning"); sheet.getRange(27, 1).setValue("Dungeoneering"); sheet.getRange(28, 1).setValue("Divination"); sheet.getRange(29, 1).setValue("Invention"); sheet.getRange(30, 1).setValue("Archaeology"); sheet.getRange(31, 1).setValue("Bounty Hunter"); sheet.getRange(32, 1).setValue("Bounty Hunter Rogue"); sheet.getRange(33, 1).setValue("Dominion Tower"); sheet.getRange(34, 1).setValue("Crucible"); sheet.getRange(35, 1).setValue("Castle Wars"); sheet.getRange(36, 1).setValue("Barbarian Assault Attacker"); sheet.getRange(37, 1).setValue("Barbarian Assault Defender"); sheet.getRange(38, 1).setValue("Barbarian ASsault Collector"); sheet.getRange(39, 1).setValue("Barbarian Assault Healer"); sheet.getRange(40, 1).setValue("Duel Tournament"); sheet.getRange(41, 1).setValue("Mobilising Armies"); sheet.getRange(42, 1).setValue("Conquest"); sheet.getRange(43, 1).setValue("Fist of Guthix"); sheet.getRange(44, 1).setValue("Gielinor Games Athletics"); sheet.getRange(45, 1).setValue("Gielinor Games Resource Race"); sheet.getRange(46, 1).setValue("WE2: Armadyl Contribution"); sheet.getRange(47, 1).setValue("WE2 Bandos Contribution"); sheet.getRange(48, 1).setValue("WE2: Armadyl PVP Kills"); sheet.getRange(49, 1).setValue("WE2: Bandos PVP Kills"); sheet.getRange(50, 1).setValue("Heist Guard Level"); sheet.getRange(51, 1).setValue("Heist Robber Level"); sheet.getRange(52, 1).setValue("CFP: 5 games"); sheet.getRange(53, 1).setValue("AF15: Cow Tipping"); sheet.getRange(54, 1).setValue("AF15: Rat Kills"); sheet.getRange(55, 1).setValue("Runescore"); sheet.getRange(56, 1).setValue("Clue Scrolls Easy"); sheet.getRange(57, 1).setValue("Clue Scrolls Med"); sheet.getRange(58, 1).setValue("Clue Scrolls Hard"); sheet.getRange(59, 1).setValue("Clue Scrolls Elite"); sheet.getRange(60, 1).setValue("Clue Scrolls Master"); sheet.getRange(61, 1).setValue("Heiest Robber Level"); } // Recursive Lookups function GetQuestData() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Quest Analysis"); var cell = sheet.getRange(4, 1); sheet.getRange("A5:A").clear(); var questName = cell.getValue(); var questArray = new Array(); GetReferences(questName, 0, 1, questArray); var resultSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Quest Analysis"); if (questArray.length > 0) { resultSheet.getRange(5, 1, questArray.length).setValues(questArray); } } var questSheet; var questColumnValues; function GetReferences(questName, currentRow, padding, questArray){ if (!questSheet) { questSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("questPrequestTable"); questColumnValues = questSheet.getRange(4, 1, questSheet.getLastRow()).getValues(); //1st is header row } searchResult = questColumnValues.findIndex(questName); //Row Index - 2 if (searchResult == -1) return currentRow; var questRowValues = questSheet.getRange(searchResult + 4, 2, 1, questSheet.getLastColumn()).getValues(); for( var i = 0; i < questRowValues[0].length; i++) { if (questRowValues[0][i]) { var paddingString = new Array(padding * 2 + 1).join(" "); if (!questArray[currentRow]) { questArray[currentRow] = []; } questArray[currentRow][0] = paddingString + questRowValues[0][i]; currentRow = currentRow + 1; currentRow = GetReferences(questRowValues[0][i], currentRow, padding + 1, questArray); } else { break; } } return currentRow; } Array.prototype.findIndex = function(search){ if(search == "") return -1; for (var i=0; i