csv 파일을 vcf로 만들기 (csv to vcf)
다음 주소록을 쓰는데 아이클라우드에 옮겨 놓으려 하니
vcf 밖에 지원이 안된다 ㅋ 다음 주소록은 csv랑 xls만 지원하고 ㅋ
그래서 만들었다 ㅋ 파이썬 코드 csv to vcf ㅋ
필드의 순서에 따라 위치를 바꾸면 됨 ㅋ
#-*- coding: utf-8 -*-
#!/usr/bin/python
lv_lines = open('cal.csv','rb').read().splitlines()
ix=1
while ix<len(lv_lines):
if len(lv_lines[ix])>10:
lv_info = lv_lines[ix].split(',')
if len(lv_info)==9:
##이름,메일,휴대폰,회사,회사전화,회사주소,집전화,집주소,그룹
##이름
open('cal.vcf','ab').write("BEGIN:VCARD\r\nVERSION:3.0\r\n")
if len(lv_info[0])>0:
open('cal.vcf','ab').write("N:;"+lv_info[0]+";;;\r\nFN:"+lv_info[0]+"\r\n")
#end if
##메일
if len(lv_info[1])>0:
open('cal.vcf','ab').write("EMAIL;TYPE=WORK;TYPE=pref;TYPE=INTERNET:"+lv_info[1]+"\r\n")
#end if
##휴대폰
if len(lv_info[2])>0:
open('cal.vcf','ab').write("TEL;TYPE=CELL;TYPE=VOICE:"+lv_info[2]+"\r\n")
#end if
##회사
if len(lv_info[3])>0:
open('cal.vcf','ab').write("ORG:"+lv_info[3]+";\r\n")
#end if
##회사전화
if len(lv_info[4])>0:
open('cal.vcf','ab').write("TEL;TYPE=WORK;TYPE=pref;TYPE=VOICE:"+lv_info[4]+"\r\n")
#end if
##회사주소
if len(lv_info[5])>0:
print lv_info[5]
#end if
##집전화
if len(lv_info[6])>0:
open('cal.vcf','ab').write("TEL;TYPE=HOME;TYPE=VOICE:"+lv_info[6]+"\r\n")
#end if
##집주소
if len(lv_info[7])>0:
print lv_info[7]
#end if
##그룹
if len(lv_info[8])>0:
open('cal.vcf','ab').write("NOTE:"+lv_info[8]+"\r\n")
#end if
open('cal.vcf','ab').write("END:VCARD\r\n")
#end if
#end if
ix+=1
#end while
0개의 덧글:
댓글 쓰기
에 가입 댓글 [Atom]
<< 홈