Created
December 29, 2020 20:05
-
-
Save HeinrichHartmann/b6b1f0953b74dfebf33a8d73c7448cea to your computer and use it in GitHub Desktop.
CSV to VCard Converer for Monica CRM
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 pandas as pd | |
import vobject | |
df = pd.read_csv("contacts.csv", index_col="Id") | |
for row in df.iterrows(): | |
rec = row[1].to_dict() | |
for k,v in rec.items(): | |
if v == "-": | |
rec[k] = None | |
elif not v: | |
rec[k] = None | |
else: | |
rec[k] = str(v) | |
j = vobject.vCard() | |
j.add('fn') # Display Name | |
j.fn.value = "{Vorname} {Nachname}".format(**rec) | |
j.add('n') | |
j.n.value = vobject.vcard.Name(family=rec["Nachname"], given=rec["Vorname"]) | |
if rec["Email"]: | |
j.add('email') | |
j.email.value = "{Email}".format(**rec) | |
if rec["Anschrift"]: | |
val = rec["Anschrift"] | |
addr = j.add('adr').value = vobject.vcard.Address( | |
street=val, | |
) | |
print(j.serialize()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment