first commit

This commit is contained in:
Eljakim Herrewijnen 2020-12-19 12:50:02 +01:00
commit 90d3ba7fe0

108
convert.py Normal file
View File

@ -0,0 +1,108 @@
'''
BEGIN:VCARD
BDAY;VALUE=DATE:1963-09-21
VERSION:3.0
N:Stenerson;Derik
FN:Derik Stenerson
ORG:Microsoft Corporation
ADR;TYPE=WORK,POSTAL,PARCEL:;Suite 101;38777 West Six Mile Road;Livonia;MI;48152;USA
TEL;TYPE=WORK,MSG:+1-425-936-5522
TEL;TYPE=WORK,FAX:+1-425-936-7329
EMAIL;TYPE=INTERNET:deriks@Microsoft.com
END:VCARD
'''
import xlrd
import pandas as pd
import os
file= 'ADRESSEN2011.xls' #If your excel file in same directory with python file u can use it
excelfile= pd.ExcelFile(file)
column = excelfile.parse('Bakkersdijk')
begin = "BEGIN:VCARD\nVERSION:4.0"
class Vcard():
def __init__(self, firstname, lastname, tussen, telephone, street, postal, city, country, email, DIV):
if(tussen == "nan"):
tussen = ""
if(telephone == "nan"):
telephone = ""
if(city == "nan"):
city = ""
if(firstname == "nan"):
firstname = ""
if(telephone == "." or telephone == "nan" or telephone == "Zuid Afrika"):
telephone = ""
if(DIV == "nan"):
DIV = ""
self.N = "N:{};{};;;\n".format(lastname, firstname)
if(tussen != ""):
self.FN = "FN:{} {} {}\n".format(firstname, tussen, lastname)
else:
self.FN = "FN:{} {}\n".format(firstname, lastname)
self.TEL = "TEL;TYPE=HOME,MSG:{}\n".format(telephone)
self.ADDR = "ADR;TYPE=WORK,POSTAL,PARCEL:;;{};{};{};{};{}\n".format(street, city, DIV, postal, country)
#self.ADDR = self.ADDR + "{};{};{};{}\n".format(street, postal, city, country)
self.ORG ="ORG:Friends\n"
self.TITLE="TITLE:\n"
def getVcard(self):
return "BEGIN:VCARD\nVERSION:3.0\n{}{}{}{}{}END:VCARD\n".format(self.N, self.FN, self.ORG, self.TEL,self.ADDR)
cards = ""
for i in range(len(column)):
'''
N:Gump;Forrest;;Mr.;
FN:Sheri Nom
TEL;TYPE#work,voice;VALUE#uri:tel:+1-111-555-1212
TEL;TYPE#home,voice;VALUE#uri:tel:+1-404-555-1212
ADR;TYPE#HOME;LABEL#"42 Plantation St.\nBaytown\, LA 30314\nUnited States of America":;;42 Plantation St.;Baytown;LA;30314;United States of America
EMAIL:sherinnom@example.com
'''
fbase = str(column["VOORNAMEN"][i])
fnames = str(column["VOORNAMEN"][i]).split(" ")
#fnames.append(str(column["VOORNAMEN"][i]).split("&"))
if("fam" in fbase):
fnames = { "Familie" }
if("&" in fbase):
fnames = str(column["VOORNAMEN"][i]).split("&")
#check for bad lastnames because of identation
lname = str(column["ACHTERNAAM"][i])
lnamesplit = str(column["ACHTERNAAM"][i]).split(" ")
if(len(lnamesplit) > 1):
lname = lnamesplit[len(lnamesplit)-1]
for name in fnames:
if(name == "en" or name == "&" or name == "mw" or name == "fam,"):
continue
if(lname == "nan"):
continue
if(name == "fam"):
name = "Familie"
fname = name
lname = lname
tussen = str(column["tussen"][i])
straat_num = str(column["STRAAT_NUM"][i])
postal = str(column["POSTCODE"][i])
city = str(column["_PLAATS"][i])
telephone = str(column["TELEFOON"][i])
DIV = str(column["DIV"][i])
country = "Netherlands"
if(DIV != "nan"):
country = "Canada"
card = Vcard(fname, lname, tussen, telephone, straat_num, postal, city, country, "", DIV)
cards += card.getVcard()
if("ruithof" in lname):
print(card.getVcard())
#print(cards)
#break
file = open("outputcards.vcf", "a")
file.write(cards)
file.close()
#N="{};{}".format(str(column["ACHTERNAAM"][i]), str(column["VOORNAMEN"][i]))
#print(N)
#if(str(column["Phone"][i])!="nan"):