Skip to content

Instantly share code, notes, and snippets.

@gchristian
Last active November 10, 2022 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gchristian/c33ad0ea6eba44461b39b4b5aca49227 to your computer and use it in GitHub Desktop.
Save gchristian/c33ad0ea6eba44461b39b4b5aca49227 to your computer and use it in GitHub Desktop.
pull fused decks into collection manager for solforge fusion
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