Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CSV to VCard Converer for Monica CRM
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