Last active
March 12, 2022 08:24
-
-
Save shep-eth/736be25878ee27184b2a07f7c260a537 to your computer and use it in GitHub Desktop.
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
const fs = require("fs"); | |
const shuffle = (array) => { | |
let currentIndex = array.length, | |
randomIndex; | |
// While there remain elements to shuffle... | |
while (currentIndex != 0) { | |
// Pick a remaining element... | |
randomIndex = Math.floor(Math.random() * currentIndex); | |
currentIndex--; | |
// And swap it with the current element. | |
[array[currentIndex], array[randomIndex]] = [ | |
array[randomIndex], | |
array[currentIndex], | |
]; | |
} | |
return array; | |
}; | |
const selectedIds = ['123', '456'] | |
const oldImagePath = "./build/images/"; | |
const oldMetadataPath = "./build/json/"; | |
const newImagePath = "./export/images/"; | |
const newMetadataPath = "./export/metadata/"; | |
const main = async () => { | |
const shuffled = shuffle(selectedIds); | |
for (const [index, id] of shuffled.entries()) { | |
const oldImage = `${oldImagePath}${id}.png`; | |
const newImage = `${newImagePath}${index}.png`; | |
const oldMetadataFile = await fs.readFileSync(`${oldMetadataPath}${id}.json`); | |
const oldMetadata = JSON.parse(oldMetadataFile); | |
const newMetadata = { | |
name: `New name format #${index}`, | |
description: 'New description', | |
image: `ipfs://NewUriToReplace/${index}.png`, | |
attributes: oldMetadata["attributes"], | |
}; | |
await fs.writeFileSync( | |
`${newMetadataPath}${index}`, | |
JSON.stringify(newMetadata) | |
); | |
await fs.copyFileSync(oldImage, newImage); | |
console.log(`Image ${oldImage} copied to ${newImage}`); | |
} | |
}; | |
main(); |
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
import glob | |
files = glob.glob("./selected/*.png") | |
def get_id(file_name): | |
return file_name.split('/')[-1].split('.')[0] | |
result = map(get_id, files) | |
print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment