duplicates

This commit is contained in:
notplants 2022-07-27 16:46:16 +02:00
parent 5cb34da08c
commit a138d6cd4a
1 changed files with 14 additions and 2 deletions

View File

@ -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: