Skip to content

Commit

Permalink
Fixed the situation where there might be two or more same name columns
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamgutgutia committed Nov 19, 2023
1 parent 5c095dc commit 053e7a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 5 additions & 1 deletion controllers/vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ def vcf():
vcard = vobject.readOne(vcfString)

jcard = jsonify({
"Name": vcard.fn.value if hasattr(vcard, 'fn') else "",
"Prefix":vcard.n.value.prefix,
"First Name":vcard.n.value.given,
"Middle Name":vcard.n.value.additional,
"Last Name":vcard.n.value.family,
"Suffix":vcard.n.value.suffix,
"Phone Number(s)": "/".join([tel.value for tel in vcard.tel_list]) if hasattr(vcard, 'tel') else "",
"E-Mail": "/".join([email.value for email in vcard.email_list]) if hasattr(vcard, 'email') else ""
})
Expand Down
14 changes: 8 additions & 6 deletions utils/vcfGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
def generateVcard(row, headers, vCards):
vcard = vobject.vCard()

fn = row.get(headers.get("First Name","NA"),"")+row.get(headers.get("Last Name","NA"),"")
fnParameters = [row.get(headers.get(string,""),"") for string in ["First Name","Middle Name","Last Name"]]
fnParameters=request.form.get("Prefix",[])+fnParameters+request.form.get("Suffix",[])
fn = " ".join(filter(None,fnParameters))
if fn:
vcard.add("fn").value = fn
else:
vcard.add("fn").value = "N/A"

vcard.add("n").value = vobject.vcard.Name(
family=row.get(headers.get("Last Name","Not Found"),""),
given=row.get(headers.get("First Name","Not Found"),""),
additional=row.get(headers.get("Middle Name","Not Found"),""),
suffix=request.form.get("suffix",""),
prefix=request.form.get("prefix","")
family=row.get(headers.get("Last Name",""),""),
given=row.get(headers.get("First Name",""),""),
additional=row.get(headers.get("Middle Name",""),""),
suffix=request.form.get("Suffix",""),
prefix=request.form.get("Prefix","")
)

fields=headers.get("Phone Number","")
Expand Down

0 comments on commit 053e7a4

Please sign in to comment.