标签:支持 pen name resource exce phone lib xml文件 oba
场景:1、IOS手机和Android手机联系人同步时有部分重复联系人。
2、很早以前的HTC手机导出的联系人中备注信息有大量乱码,且很多联系人生日被设置为1970-01-01,导致生日提醒软件产生骚扰问题。
适用设备平台:IOS,Android
联系人备份软件:腾讯应用宝
关键字:Python,xml
整体步骤:
1、下载腾讯应用宝(非打广告,该支持excel,xml,csv等多种格式的联系人备份文件导入导出)
2、手机连接PC,打开应用宝,导出联系人为xml文件。
3、代码实现,生成新的联系人xml文件Contactrsp.xml:
1 #!/usr/bin/env python 2 # encoding: utf-8 3 """ 4 @version: v1.0 5 @author: Elijahxb 6 @time: 2017/12/3 12:13 7 """ 8 import xml.etree.ElementTree as ET 9 from lib.Global.GlobalPath import *#可自行定义资源文件路径变量resource_path 10 import os 11 12 xmlPath = os.path.join(resource_path,"XML","FullContact.xml") 13 tree = ET.parse(xmlPath) 14 root = tree.getroot() 15 con_node_list = root.findall("Contact") 16 print len(con_node_list) 17 index = 0 18 con_dic = {} 19 for con_node in con_node_list: 20 PhoneList_node = con_node.find("PhoneList") 21 if PhoneList_node is not None: 22 con_name = con_node.find("Name").text 23 PhoneNumber_list = PhoneList_node.findall("Phone") 24 if PhoneNumber_list: 25 con_dic[con_name] = [] 26 for PhoneNumber in PhoneNumber_list: 27 telephone = PhoneNumber.text 28 if telephone[:4] == ("+86-"): 29 telephone = telephone[4:] 30 con_dic[con_name].append(telephone) 31 elif telephone[:3] == "400" or telephone[:4] == "0400" or telephone[:3] == "106": 32 pass 33 elif telephone == "18000000000": 34 pass 35 elif u"专线" in con_name: 36 pass 37 else: 38 con_dic[con_name].append(telephone) 39 if con_dic[con_name] == []: 40 con_dic.pop(con_name) 41 index += 1 42 print len(con_dic) 43 44 45 root = ET.Element("Contacts") 46 for k in con_dic: 47 print k,con_dic[k] 48 Contact_node = ET.SubElement(root,"Contact") 49 Name_node = ET.SubElement(Contact_node,"Name") 50 Name_node.text = k 51 PhoneList_node = ET.SubElement(Contact_node,"PhoneList") 52 for telephone in con_dic[k]: 53 phone_node = ET.SubElement(PhoneList_node,"Phone",{"Type":"2"}) 54 phone_node.text = telephone 55 56 tree = ET.ElementTree(root) 57 f_path = os.path.join(resource_path,"XML","Contactrsp.xml") 58 tree.write(f_path,encoding="utf-8")
4、删除手机联系人,导入Contactrsp.xml文件,结束。
5、实现效果:a.同名联系人的号码会被合并到同名联系人下。b.自定义过滤器,将拦截软件生成的400,106等号码删除,名称为**专线**的号码删除。
标签:支持 pen name resource exce phone lib xml文件 oba
原文地址:http://www.cnblogs.com/elijahxb/p/7966054.html