Last active
May 31, 2018 10:17
-
-
Save tongphe/810bcaf1c6612b0abc1e6a9ac704e15b to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# python tttt.py contacts.vcf > import_icloud.vcf | |
import vobject | |
import sys | |
phone_dict = { | |
'120': '70', '121': '79', '122': '77', '126': '76', '128': '78', # MOBI | |
'123': '83', '124': '84', '125': '85', '127': '81', '129': '82', # VINA | |
'162': '32', '163': '33', '164': '34', '165': '35', '166': '36', '167': '37', '168': '38', '169': '39', #VIETTEL | |
'186': '56', '188': '58', #VNM | |
'199': '59', #GM | |
} | |
def normalizePhone(number): | |
phone = number.translate(None,'-.() ') | |
phone = phone.replace('+84', '0') | |
if len(phone) == 11: | |
try: | |
phone = phone[0] + phone_dict[phone[1:4]] + phone[4:] | |
except: | |
pass | |
return phone | |
vfile = sys.argv[1] | |
vcontent = open(vfile) | |
for vcard in vobject.readComponents(vcontent): | |
try: | |
for tel in vcard.contents['tel']: | |
tel.value = normalizePhone(tel.value) | |
except: | |
pass | |
sys.stdout.write(vcard.serialize()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment