Created
November 27, 2014 11:46
-
-
Save icedraco/bdd2fb00823a5a08f227 to your computer and use it in GitHub Desktop.
A script that imports a lot of UTF-8-encoded VCF files into a single list for use with programs like Excel
This file contains hidden or 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 a [large] group of UTF-8-encoded VCF files into a single | |
| # "<name>\t<phone>\r\n" text file for use with Excel or other programs. | |
| # | |
| # Requires: vobject (which requires dateutil) | |
| # | |
| # Author: IceDragon <icedragon@quickfox.org> | |
| # http://www.icerealm.org/contact | |
| import vobject | |
| from glob import glob | |
| DATA = "./VCF" | |
| OUTPUT = "imported.txt" | |
| ###--# Functions #--########################################################### | |
| def extractData(fname): | |
| vobj = vobject.readOne(open(fname,'r'), allowQP=True) | |
| result = {"name": vobj.getChildValue("fn", "").encode('utf-8'), "tel": []} | |
| for child in vobj.getChildren(): | |
| if child.name == "TEL": | |
| result['tel'] += [ child.value.encode('utf-8') ] | |
| return result | |
| vcf = glob(DATA + "/*.vcf") | |
| fd = open(OUTPUT,'w') | |
| for data in map(extractData, vcf): | |
| if len(data['tel']) > 0: | |
| for tel in data['tel']: | |
| fd.write("%s\t%s\r\n" % (data['name'], tel)) | |
| else: | |
| fd.write("%s\t\r\n" % (data['name'])) | |
| fd.close() | |
| print "OK" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment