Last active
March 26, 2019 15:41
-
-
Save makkoncept/edcb22a2754aa1074d4258ee8d990b59 to your computer and use it in GitHub Desktop.
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 | |
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