Created
April 5, 2024 12:32
-
-
Save jelofsson/d1553423e9003e26b5f637e406acfb6f to your computer and use it in GitHub Desktop.
Remove None Attributes - nft-generator-py helper
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
import os | |
import json | |
import glob | |
import re | |
# Get all JSON files in the directory | |
json_files = glob.glob('output/metadata/*.json') | |
for json_file in json_files: | |
# Check if the filename is a number | |
filename = os.path.basename(json_file) | |
filename_without_extension = os.path.splitext(filename)[0] | |
if not re.match(r'^\d+$', filename_without_extension): | |
continue | |
# Load the JSON data | |
with open(json_file, 'r') as f: | |
data = json.load(f) | |
# Remove attributes with the value "None" | |
data['attributes'] = [attr for attr in data['attributes'] if attr['value'] != 'None'] | |
# Write the modified data back to the file | |
with open(json_file, 'w') as f: | |
json.dump(data, f, indent=4) | |
# Load the JSON data | |
with open('output/metadata/all-objects.json', 'r') as f: | |
data = json.load(f) | |
# Remove attributes with the value "None" from all objects | |
for obj in data: | |
obj['attributes'] = [attr for attr in obj['attributes'] if attr['value'] != 'None'] | |
# Write the modified data back to the file | |
with open('output/metadata/all-objects.json', 'w') as f: | |
json.dump(data, f, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment