2021-11-27 01:25:07 +00:00
|
|
|
# Purpose:
|
|
|
|
# This file sorts the NFT DNA from NFTRecord.json and exports it to a given number of Batch#.json files set by nftsPerBatch
|
|
|
|
# in config.py.
|
|
|
|
|
2021-10-19 19:10:54 +00:00
|
|
|
import bpy
|
|
|
|
import os
|
2021-10-30 15:29:02 +00:00
|
|
|
import json
|
|
|
|
import random
|
|
|
|
|
|
|
|
|
2022-02-02 15:37:42 +00:00
|
|
|
def makeBatches(nftName, maxNFTs, nftsPerBatch, save_path, batch_json_save_path):
|
|
|
|
Blend_My_NFTs_Output = os.path.join(save_path, "Blend_My_NFTs Output", "NFT_Data")
|
|
|
|
NFTRecord_save_path = os.path.join(Blend_My_NFTs_Output, "NFTRecord.json")
|
2021-11-27 01:25:07 +00:00
|
|
|
|
2022-02-02 15:37:42 +00:00
|
|
|
DataDictionary = json.load(open(NFTRecord_save_path))
|
2021-10-19 19:10:54 +00:00
|
|
|
|
2022-01-28 21:56:59 +00:00
|
|
|
numNFTsGenerated = DataDictionary["numNFTsGenerated"]
|
|
|
|
hierarchy = DataDictionary["hierarchy"]
|
|
|
|
DNAList = DataDictionary["DNAList"]
|
2021-10-19 19:10:54 +00:00
|
|
|
|
2022-02-02 15:37:42 +00:00
|
|
|
numBatches = maxNFTs / nftsPerBatch
|
2021-10-19 19:10:54 +00:00
|
|
|
|
2022-02-02 15:37:42 +00:00
|
|
|
print(f"To generate batches of {nftsPerBatch} DNA sequences per batch, with a total of {numNFTsGenerated}"
|
2022-01-28 21:56:59 +00:00
|
|
|
f" possible NFT DNA sequences, the number of batches generated will be {numBatches}")
|
2021-10-19 19:10:54 +00:00
|
|
|
|
2022-02-02 15:37:42 +00:00
|
|
|
# Clears the Batch Data folder of Batches:
|
|
|
|
batchList = os.listdir(batch_json_save_path)
|
|
|
|
|
|
|
|
if batchList:
|
|
|
|
for i in batchList:
|
|
|
|
batch = os.path.join(batch_json_save_path, i)
|
|
|
|
if os.path.exists(batch):
|
|
|
|
os.remove(
|
|
|
|
os.path.join(batch_json_save_path, i)
|
|
|
|
)
|
|
|
|
|
2022-01-28 21:56:59 +00:00
|
|
|
i = 0
|
|
|
|
while i < numBatches:
|
|
|
|
batchDictionary = {}
|
|
|
|
BatchDNAList = []
|
2021-10-19 19:10:54 +00:00
|
|
|
|
2022-01-28 21:56:59 +00:00
|
|
|
j = 0
|
2022-02-02 15:37:42 +00:00
|
|
|
while (j < nftsPerBatch) and (DNAList):
|
2022-01-28 21:56:59 +00:00
|
|
|
oneDNA = random.choice(DNAList)
|
2022-03-26 03:47:54 +00:00
|
|
|
BatchDNAList.append({
|
|
|
|
oneDNA: {"Complete": False}
|
|
|
|
})
|
2022-01-28 21:56:59 +00:00
|
|
|
DNAList.remove(oneDNA)
|
|
|
|
j += 1
|
2021-10-19 19:10:54 +00:00
|
|
|
|
2022-01-28 21:56:59 +00:00
|
|
|
batchDictionary["NFTs_in_Batch"] = int(len(BatchDNAList))
|
|
|
|
batchDictionary["hierarchy"] = hierarchy
|
|
|
|
batchDictionary["BatchDNAList"] = BatchDNAList
|
2021-10-19 19:10:54 +00:00
|
|
|
|
2022-01-28 21:56:59 +00:00
|
|
|
batchDictionaryObject = json.dumps(batchDictionary, indent=1, ensure_ascii=True)
|
2021-10-19 19:10:54 +00:00
|
|
|
|
2022-02-02 15:37:42 +00:00
|
|
|
with open(os.path.join(batch_json_save_path, ("Batch{}.json".format(i + 1))), "w") as outfile:
|
2022-01-28 21:56:59 +00:00
|
|
|
outfile.write(batchDictionaryObject)
|
2021-10-20 01:29:20 +00:00
|
|
|
|
2022-01-28 21:56:59 +00:00
|
|
|
i += 1
|
2021-10-19 19:10:54 +00:00
|
|
|
|
2022-03-26 03:47:54 +00:00
|
|
|
if len(DNAList) > 0: # Add to Checks.py
|
2022-01-28 21:56:59 +00:00
|
|
|
print(f"One batch could not be filled completely and will contain {len(DNAList)} NFTs.")
|
2021-11-12 19:06:57 +00:00
|
|
|
|
2022-01-28 21:56:59 +00:00
|
|
|
incompleteBatch = {"NFTs_in_Batch": int(len(DNAList)), "hierarchy": hierarchy, "BatchDNAList": DNAList}
|
2021-11-01 04:11:48 +00:00
|
|
|
|
2022-01-28 21:56:59 +00:00
|
|
|
incompleteBatch = json.dumps(incompleteBatch, indent=1, ensure_ascii=True)
|
2021-10-19 19:10:54 +00:00
|
|
|
|
2022-02-02 15:37:42 +00:00
|
|
|
with open(os.path.join(batch_json_save_path, ("Batch{}.json".format(i + 1))), "w") as outfile2:
|
2022-01-28 21:56:59 +00:00
|
|
|
outfile2.write(incompleteBatch)
|