diff --git a/csv_to_wiki.py b/csv_to_wiki.py index 124eb7f..3a342db 100644 --- a/csv_to_wiki.py +++ b/csv_to_wiki.py @@ -10,11 +10,23 @@ OUTPUT_PATH = "/Volumes/mdrive/computer/projects/csv-to-wiki/output" def csv_to_wiki(): print("hello") + os.system("rm -r {}/*".format(OUTPUT_PATH)) + with open('contacts.csv', 'r') as csv_file: reader = csv.DictReader(csv_file) for row in reader: - name = row["Name"] - file_path = os.path.join(OUTPUT_PATH, name + ".md") + base_name = row["Name"] + name = base_name + count = 1 + new_name_found = False + while not new_name_found: + file_path = os.path.join(OUTPUT_PATH, name + ".md") + if os.path.exists(file_path): + count = count + 1 + name = base_name + str(count) + else: + new_name_found = True + with open(file_path, 'w') as f: for key, value in row.items(): if value: