Last active
May 28, 2017 00:03
-
-
Save K-Wu/0413a70b69cd33116d0d16d14e223ab3 to your computer and use it in GitHub Desktop.
A script to convert csv file to vcf file, which can be imported to Contact App on mobile phone.
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 python3 | |
# -*- coding: utf-8 -*- | |
#A script to convert csv file to vcf file, which can be imported to Contact App on mobile phone. | |
#eesast csv format 姓名,性别,生日,农历生日,班级,宿舍号,手机号,电子邮箱,部门,GitHub用户名,职位 | |
""" | |
vcf format | |
BEGIN:VCARD | |
VERSION:3.0 | |
FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E5=90=B4=E6=98=86 | |
BDAY;VALUE=text:1900-00-00 | |
TEL;TYPE=VOICE,CELL;VALUE=text:13000000000 | |
EMAIL;TYPE=HOME,INTERNET,pref:abcdefgh@mails.tsinghua.edu.cn | |
ADR;TYPE=WORK:K-Wu | |
END:VCARD | |
""" | |
import codecs | |
eesast_csv_filename="eesast16.txt" | |
vcf_filename="eesast.vcf" | |
with open(vcf_filename,'w') as vcf_fd: | |
with open(eesast_csv_filename,encoding="utf8") as csv_fd: | |
csv_fd.readline() | |
for line in csv_fd: | |
vcf_fd.write("BEGIN:VCARD\n") | |
vcf_fd.write("VERSION:3.0\n") | |
contact=line.split(",") | |
name=contact[0].encode("utf8")#converted "吴昆" to bytes | |
name='='.join('{:02x}'.format(x) for x in name).upper() | |
birthday=contact[2] | |
mobile=contact[6] | |
vcf_fd.write("FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:={}\n".format(name)) | |
vcf_fd.write("BDAY;VALUE=text:{}\n".format(birthday)) | |
vcf_fd.write("EL;TYPE=VOICE,CELL;VALUE=text:{}\n".format(mobile)) | |
vcf_fd.write("END:VCARD\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment