I'm trying to save the products.json and index.html files to the folder I create in this snippet. How do I do this?
It doesn't work as it stands. The files don't go inside of the directory, they just overwrite each other in the root directory as the script cycles through.
with open("products.json", "w") as write_file:
json.dump({'items': all_products}, write_file)
dirName = category_name.strip().lower().replace(' ', '-')
try:
os.mkdir(dirName)
print("Directory ", dirName, " created")
except FileExistsError:
print("Directory ", dirName, " already exists")
with open('cat_template.html') as file_:
template = Template(file_.read())
html = template.render(cat_dict)
with open('index.html', 'w') as write_file:
write_file.write(html)
print("Success" + single_url + " written to file")