Created
September 16, 2022 17:18
-
-
Save nclslbrn/52b271f59c5836a60d3f748e18a1d63c to your computer and use it in GitHub Desktop.
NodeJS script to sort collectors by editions (from multiple tokens) collectors.csv from https://fxcollectors.stroep.nl/
This file contains 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
const fs = require('fs') | |
function getCollectors(number) { | |
const data = fs.readFileSync('./collectors.csv', 'utf8') | |
let lines = data.split('\n').slice(1) | |
const collectorsObject = {} | |
lines.forEach((l) => { | |
if(l.length === 0) return | |
const row = l.split(' ') | |
if (row.length > 0) { | |
const address = row[0] | |
const editions = parseInt(row[1].replace(/[\])}[{(]/g, '')) | |
if(collectorsObject[address] === undefined) { | |
collectorsObject[address] = editions | |
} else { | |
collectorsObject[address] += editions | |
} | |
} | |
}) | |
const collectorsArray = Object.keys(collectorsObject).map( | |
function (e) { | |
return { | |
address: e, | |
editions: collectorsObject[e] | |
} | |
}) | |
const sortedCollectors = collectorsArray.sort(({editions: a}, {editions: b}) => b-a) | |
for (let i = 0; i < number; i++) { | |
console.log( | |
`${sortedCollectors[i]['editions']}eds /https://www.fxhash.xyz/pkh/${sortedCollectors[i]['address']}/collection` | |
) | |
} | |
} | |
getCollectors(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment