generate_wechat_image.py 文件源码

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

项目:WXHeadImage 作者: zhaokefei 项目源码 文件源码
def get_friend_imgs(save_path, get_img_nums=100):
    # ????????
    if os.path.exists(save_path):
        save_path = input(u'????????????????: ')
    os.mkdir(save_path)
    # ??????
    friends = itchat.get_friends()
    if get_img_nums > len(friends):
        get_img_nums = len(friends)
        print(u'?????????????????????? %s' % len(friends))
    for num, friend in enumerate(friends):
        friend_name = friend['NickName'] or friend['UserName']
        # ???????????????
        friend_name = re.sub(r'[\s+]', '_', friend_name)
        friend_img = itchat.get_head_img(userName=friend['UserName'])
        with open(save_path + '/' + friend_name + str(num+1).zfill(3) + '.jpg', 'wb') as f:
            print(u'???? %s ???, ???? %s ?' % (friend_name, get_img_nums-num))
            f.write(friend_img)
        if num > get_img_nums:
            print(u'%s ???????' % get_img_nums)
            break
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号