Last active
November 10, 2022 03:08
-
-
Save gchristian/c33ad0ea6eba44461b39b4b5aca49227 to your computer and use it in GitHub Desktop.
pull fused decks into collection manager for solforge fusion
This file contains hidden or 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 pullFused(){ | |
var ui = SpreadsheetApp.getUi(); | |
var username = ui.prompt("Enter your Solforge Fusion Username"); | |
console.log(username); | |
//the user name for which collection to grab | |
//fetch fused deck from api endpoint | |
var response = UrlFetchApp.fetch('https://ul51g2rg42.execute-api.us-east-1.amazonaws.com/main/fuseddeck?pageSize=36&username='+username.getResponseText()); | |
var fused_data = JSON.parse(response.getContentText()); | |
//grabbing all the bits of the sheet i need | |
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var fusedDecksTab = spreadsheet.getSheetByName("Fused decks"); | |
var lastRow = fusedDecksTab.getLastRow(); | |
var existingFused = fusedDecksTab.getRange("A2:A").getValues(); | |
all_fused_decks = []; | |
all_names = []; | |
existingFused.forEach(function(currentDeck) { | |
if (currentDeck[0] != "") | |
all_names.push(currentDeck[0]); | |
}) | |
fused_data['Items'].forEach(function(currentDeck) { | |
if (!all_names.includes(currentDeck['name']) && (currentDeck['isArchived'] == null || currentDeck['isArchived'] != true)) | |
{ | |
all_fused_decks.push([currentDeck['name'], | |
currentDeck['myDecks'][0]['name'], | |
currentDeck['myDecks'][1]['name'], | |
"https://solforgefusion.com/fused/" + currentDeck['id']] | |
); | |
} | |
}) | |
if (all_fused_decks.length > 0){ | |
fusedDecksTab.getRange(lastRow + 1,1,all_fused_decks.length, 4).setValues(all_fused_decks); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment