Python——公司又双叒叕更新通讯录了,利用itchat实现微信速查公司通讯录

公司又双叒叕更新通讯录了,着急联系同事却发现手机通讯录里没有保存他的手机号码,急不急?气不气?最近在学 Python litchat模块,聪明的我想到一个办法借助微信实现通讯录速查。

思路:

  • 1、通讯录(exce1)转换成.csv
  • 2、 py thon读取通讯录.csv通过文本操作创建联系人dict
  • 3、itchat监控接收消息,如果在dict中匹配到key,返回 iteam
  • 4、支持模糊匹配,比如输入“毛?”,匹配出毛姓的所有iteam
  • 5、暂时就想到这此
address_list=address.split('\n')
#address_dic={'姓名':'','手机号':'','小号':'','内线':'','座机':'','邮箱':''}
ls= ['name','mob','short','tel','tel1','email']
address_dic={}#包含字典的dict
for i in range(len(address_list)):
    temp=address_list[i].split(',')
    #print(dict(zip(ls,temp)))
    temp_dic=dict(zip(ls,temp))
    address_dic.update({temp_dic['name']:{'name':temp_dic['name'],
                                         'mob':temp_dic['mob'],
                                         'short':temp_dic['short'],
                                         'tel':temp_dic['tel'],
                                         'tel1':temp_dic['tel1'],
                                         'email':temp_dic['email']
                                        }})
                                        
def mathcing(match):    #模糊匹配,匹配模式:徐*  ,返回匹配到的姓名列表
    ls_temp=[]
    for i in address_dic.keys():
        if match[0] in i and match[1:]=='*':
            #print('徐在姓氏表里!')
            ls_temp.append(i)
    #print(ls_temp)
    return(ls_temp)
   
if msg_content in address_dic.keys():
         #发送文字信息
     itchat.send_msg(address_dic[msg_content]['name']+'的通讯录::'+'\n'+'手机号码:'+address_dic[msg_content]['mob']+'\n手机小号:'+address_dic[msg_content]['short']+'\n座机内线:'+address_dic[msg_content]['tel']+'\n座机外线:'+address_dic[msg_content]['tel1']+'\nEmail:'+address_dic[msg_content]['email'], msg['FromUserName'])

猜你喜欢

转载自blog.csdn.net/weixin_43087443/article/details/88046016