36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
import os
|
|
import json
|
|
|
|
def list_files_in_directory(directory_path):
|
|
# Get a list of all files in the directory with their respective attributes
|
|
files_list = []
|
|
file_id = 1
|
|
|
|
for root, dirs, files in os.walk(directory_path):
|
|
for file in files:
|
|
file_data = {
|
|
"id": file_id,
|
|
"name": os.path.splitext(file)[0],
|
|
"photo": f'{os.path.dirname(directory_path)}/{file}',
|
|
"price": 25, # Default price, change as needed
|
|
"size": "Youth-S/M/L/2XL | Adult-S/M/L/2XL", # Default size, change as needed
|
|
"inStock": "yes", # Default stock status, change as needed
|
|
"favorite": "no", # Default favorite status, change as needed
|
|
"description": "It's not an option.." # Default description, change as needed
|
|
}
|
|
files_list.append(file_data)
|
|
file_id += 1
|
|
|
|
return files_list
|
|
|
|
def write_files_to_json(directory_path, output_json_file):
|
|
files_list = list_files_in_directory(directory_path)
|
|
|
|
# Write the list to a JSON file
|
|
with open(output_json_file, 'w') as json_file:
|
|
json.dump(files_list, json_file, indent=4)
|
|
|
|
# Example usage
|
|
directory_path = '.'
|
|
output_json_file = f'files_list.json'
|
|
write_files_to_json(directory_path, output_json_file) |