wechat.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:WeChatBot 作者: crane-yuan 项目源码 文件源码
def save_contacts_info(self):
        import xlsxwriter
        from PIL import Image
        from io import BytesIO
        workbook = xlsxwriter.Workbook(os.path.join(self.temp_pwd,'contact_list.xlsx')) #?????
        '''
        ?????sheet:
            sheet1
        '''
        sheet1 = workbook.add_worksheet() #??sheet
        row0 = [u'NickName', u'HeadImgUrl', u'RemarkName']

        sheet1.set_column('A:C', 18)
        #?????
        for i in range(0,len(row0)):
            sheet1.write(0,i,row0[i])

        for i in range(0, len(self.contact_list)):
            try:
                sheet1.set_row(i+1, 100)
                sheet1.write(i+1,0,self.contact_list[i]['NickName'])
                # ???????https://wx2.qq.com
                url ="https://wx.qq.com" + self.contact_list[i]['HeadImgUrl']
                print(url)
                r = self.session.get(url)
                pic = Image.open(BytesIO(r.content))
                pic.save(os.path.join(self.temp_pwd, 'img', self.contact_list[i]['NickName']+'.jpg'))
                #sheet1.write(i+1,1,self.contact_list[i]['HeadImgUrl'])
                sheet1.insert_image(i+1,1,os.path.join(self.temp_pwd, 'img', self.contact_list[i]['NickName']+'.jpg'))
                sheet1.write(i+1,2,self.contact_list[i]['RemarkName'])
            except Exception as e:
                print(e)
        workbook.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号