ケータイの連絡先データをiPhoneに移行
目標
環境
データを取り出す
下のサイトを参考にauデータお預かりアプリを利用してmicroSDカードにデータを移行する。 www.au.com
データ整形
連作先データはjson形式で保存されるのでpythonでvfc形式に変換する。
取り出したjsonの形式
- 名前 佐藤太郎
- 電話番号 080 1111 2222 の場合
{ "accountName": "Contacts", "accountType": "jp.kyocera.localcontacts", "customRington": null, "email": [], "event": [], "groupMembership": [5], "im": [], "nickname": { "data1": "", "data2": "", "data3": "" }, "note": [], "organization": [], "phone": [{ "data1": " { "accountName": "Contacts", "accountType": "jp.kyocera.localcontacts", "customRington": null, "email": [], "event": [], "groupMembership": [5], "im": [], "nickname": { "data1": "", "data2": "", "data3": "" }, "note": [], "organization": [], "phone": [{ "data1": "07020228047", "data2": "3", "data3": null }], "photo": { "data15": null, "dislayPhotoName": null }, "relation": [], "sendToVoicemail": 0, "sipAddress": [], "starred": 0, "structuredName": { "data1": "太郎", "data2": "", "data3": "佐藤", "data4": null, "data5": null, "data6": null, "data7": "タロウ", "data8": null, "data9": "サトウ" }, "structuredPostal": [], "website": [] },", "data2": "3", "data3": null }], "photo": { "data15": null, "dislayPhotoName": null }, "relation": [], "sendToVoicemail": 0, "sipAddress": [], "starred": 0, "structuredName": { "data1": "太郎", "data2": "", "data3": "佐藤", "data4": null, "data5": null, "data6": null, "data7": "タロウ", "data8": null, "data9": "サトウ" }, "structuredPostal": [], "website": [] },
vfc形式の例
BEGIN:VCARD VERSION:3.0 N:性;名 FN:名 性 X-PHONETIC-LAST-NAME:性フリガナ X-PHONETIC-NAME:名フリガナ TEL;type=CELL;type=VOICE;type=pref:電話番号 END:VCARD
プログラム
必要な情報をjsonから摘出し、vfc形式のファイルを出力するプログラムを作成する。
import json output_contacts = open('./output.vcf', 'w', encoding='utf-8') json_file = open('./Contacts1.json', 'r') json_load = json.load(json_file) for i in range(0, 50): output_contacts.write('BEGIN:VCARD\n') output_contacts.write('VERSION:3.0\n') firstname = json_load[i]['structuredName']['data1'] lastname = json_load[i]['structuredName']['data3'] output_contacts.write('N:' + lastname + ';' + firstname + '\n') output_contacts.write('FN:' + firstname + ' ' + lastname + '\n') output_contacts.write('X-PHONETIC-LAST-NAME:' + json_load[i]['structuredName']['data9'] + '\n') output_contacts.write('TEL;type=CELL;type=VOICE;type=pref:' + json_load[i]['phone'][0]['data1'] + '\n') output_contacts.write('END:VCARD' + '\n') json_file.close() output_contacts.close()