Skip to content

Instantly share code, notes, and snippets.

@makkoncept
Last active March 26, 2019 15:41
Show Gist options
  • Save makkoncept/edcb22a2754aa1074d4258ee8d990b59 to your computer and use it in GitHub Desktop.
Save makkoncept/edcb22a2754aa1074d4258ee8d990b59 to your computer and use it in GitHub Desktop.
import os
def update_content(file_path, content_list):
with open(file_path, 'w') as f:
f.writelines(content)
dirs = os.listdir(os.getcwd())
print(dirs)
for dir in dirs:
if dir == os.path.basename(__file__) or dir == "contents.lr":
continue
content_path = os.path.join(dir, "contents.lr")
with open(content_path) as f:
content = f.readlines()
old_categories = content[2][12:]
old_categories_list = old_categories.strip().split(',')
new_categories = "categories:\n"
if not(len(old_categories_list) == 1 and old_categories_list[0] == ""):
for category in old_categories_list:
new_categories += f"{category.strip()}\n"
content[2] = new_categories
update_content(content_path, content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment