Last active
November 18, 2023 04:46
-
-
Save yin8086/4132006 to your computer and use it in GitHub Desktop.
VCard process to get the person who has phone numbers
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
# -*- coding: utf-8 -*- | |
import vobject, sys, codecs | |
from os import path | |
def hasTel(lineList): | |
for line in lineList: | |
if line[:len('TEL;')] == 'TEL;': | |
return True | |
return False | |
if len(sys.argv)==1: | |
print u'缺少参数' | |
sys.exit(0) | |
elif not path.isfile(sys.argv[1]): | |
print u'目标文件不存在' | |
sys.exit(0) | |
srcVCF = codecs.open(sys.argv[1], 'rb', 'utf8') | |
destVCF = codecs.open(sys.argv[1][:-4]+'_new.vcf', 'wb', 'utf8') | |
# srcVCF = open(sys.argv[1], 'rb') | |
# destVCF = open(sys.argv[1][:-4]+'_new.vcf', 'wb') | |
state = 0 | |
outString = [] | |
for line in srcVCF: | |
if line[:len('BEGIN:VCARD')] == 'BEGIN:VCARD' and state ==0: | |
outString.append(line) | |
state = 1 | |
elif line[:len('END:VCARD')] == 'END:VCARD' and state == 1: | |
if hasTel(outString): | |
for strEle in outString: | |
destVCF.write(strEle) | |
outString = [] | |
destVCF.write(line) | |
state = 0 | |
elif state == 1: | |
outString.append(line) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment