Skip to content

Instantly share code, notes, and snippets.

@tunnckoCore
Last active April 25, 2025 02:34
Show Gist options
  • Save tunnckoCore/d731fb3f896b9bf6d9bf24a068d305a3 to your computer and use it in GitHub Desktop.
Save tunnckoCore/d731fb3f896b9bf6d9bf24a068d305a3 to your computer and use it in GitHub Desktop.
comrades to ranks
async function fetchAndProcessComrades() {
const url = 'https://rawcdn.githack.com/NoMoreLabs/Call-Data-Comrades/refs/heads/main/metadata/call-data-comrades.json';
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
if (!data || !data.collection_items || !Array.isArray(data.collection_items)) {
throw new Error("Invalid data structure received.");
}
let csvString = "name,rank\n"; // Add CSV header
data.collection_items.forEach(item => {
const name = `Comrade ${item.index}`;
const rankAttribute = item.attributes.find(attr => attr.trait_type === 'Rank');
const rank = rankAttribute ? rankAttribute.value : 'N/A'; // Handle cases where rank might not be present
csvString += `${name},${rank}\n`; // Add data row
});
return csvString;
} catch (error) {
console.error("Error fetching and processing comrades:", error);
return null; // Or throw the error, depending on how you want to handle it
}
}
// Example usage:
fetchAndProcessComrades().then(async csvOutput => {
if (csvOutput) {
console.log(csvOutput);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment