From 5cb34da08cddf5a7626da0c2a88d545869fc12f9 Mon Sep 17 00:00:00 2001 From: notplants Date: Wed, 27 Jul 2022 15:54:41 +0200 Subject: [PATCH] working --- .gitignore | 3 +++ csv_to_wiki.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .gitignore create mode 100644 csv_to_wiki.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3fdba3c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +contacts.csv +venv +output diff --git a/csv_to_wiki.py b/csv_to_wiki.py new file mode 100644 index 0000000..124eb7f --- /dev/null +++ b/csv_to_wiki.py @@ -0,0 +1,35 @@ +import csv +import os + +# Name,Given Name,Additional Name,Family Name,Yomi Name,Given Name Yomi,Additional Name Yomi,Family Name Yomi,Name Prefix,Name Suffix,Initials,Nickname,Short Name,Maiden Name,Birthday,Gender,Location,Billing Information,Directory Server,Mileage,Occupation,Hobby,Sensitivity,Priority,Subject,Notes,Language,Photo,Group Membership,E-mail 1 - Type,E-mail 1 - Value,E-mail 2 - Type,E-mail 2 - Value,E-mail 3 - Type,E-mail 3 - Value,IM 1 - Type,IM 1 - Service,IM 1 - Value,Phone 1 - Type,Phone 1 - Value,Phone 2 - Type,Phone 2 - Value,Phone 3 - Type,Phone 3 - Value,Phone 4 - Type,Phone 4 - Value,Address 1 - Type,Address 1 - Formatted,Address 1 - Street,Address 1 - City,Address 1 - PO Box,Address 1 - Region,Address 1 - Postal Code,Address 1 - Country,Address 1 - Extended Address,Organization 1 - Type,Organization 1 - Name,Organization 1 - Yomi Name,Organization 1 - Title,Organization 1 - Department,Organization 1 - Symbol,Organization 1 - Location,Organization 1 - Job Description,Relation 1 - Type,Relation 1 - Value,Relation 2 - Type,Relation 2 - Value,Relation 3 - Type,Relation 3 - Value,Relation 4 - Type,Relation 4 - Value,Relation 5 - Type,Relation 5 - Value,Relation 6 - Type,Relation 6 - Value,Relation 7 - Type,Relation 7 - Value,Relation 8 - Type,Relation 8 - Value,Relation 9 - Type,Relation 9 - Value,Relation 10 - Type,Relation 10 - Value,Relation 11 - Type,Relation 11 - Value,Website 1 - Type,Website 1 - Value,Website 2 - Type,Website 2 - Value,Website 3 - Type,Website 3 - Value,Website 4 - Type,Website 4 - Value,Website 5 - Type,Website 5 - Value,Website 6 - Type,Website 6 - Value,Website 7 - Type,Website 7 - Value,Event 1 - Type,Event 1 - Value + +FILTER_KEYS = ["Given Name", "Family Name"] + +OUTPUT_PATH = "/Volumes/mdrive/computer/projects/csv-to-wiki/output" + +def csv_to_wiki(): + print("hello") + + 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") + with open(file_path, 'w') as f: + for key, value in row.items(): + if value: + if not key in FILTER_KEYS: + if key == "Group Membership": + words = list(map(lambda word: "#" + word.replace(" ", ""), value.split(":::"))) + value = " ".join(words) + value = value.replace(" ::: ", "\n") + debug_line = "{}: {}".format(key, value) + output_line = "{}".format(value) + print(debug_line) + f.write(output_line + "\n") + + print("*************") + + +if __name__ == '__main__': + csv_to_wiki() \ No newline at end of file