wxpy玩转weChat

What is wxpy?

wxpy 在 itchat 的基础上,通过大量接口优化提升了模块的易用性,并进行丰富的功能扩展。

How to install?

sudo pip3 install -U wxpy

简单上手

import wxpy     # 导入wxpy模块
bot = wxpy.Bot()    # 初始化机器人,扫码登陆
 ```

# 打印好友信息
![](https://upload-images.jianshu.io/upload_images/9107736-98a097e1c5f518d7.jpeg?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)
```python
my_friends = bot.friends()
print(my_friends)




<div class="se-preview-section-delimiter"></div>

统计好友性别

sex_dict = {'male': 0, 'female': 0, 'other': 0}

for friend in my_friends:
    if friend.sex == 1:
        sex_dict['male'] += 1
    elif friend.sex == 2:
        sex_dict['female'] += 1
    else:
        sex_dict['other'] += 1

print(sex_dict)
print("Total numbers of my friends: ", len(my_friends))




<div class="se-preview-section-delimiter"></div>

统计好友省份分布

province_dict = {
                    '北京': 0, '上海': 0, '天津': 0, '重庆': 0, '西藏': 0,
                    '河北': 0, '山西': 0, '吉林': 0, '辽宁': 0, '黑龙江': 0,
                    '陕西': 0, '甘肃': 0, '青海': 0, '山东': 0, '福建': 0,
                    '浙江': 0, '台湾': 0, '河南': 0, '湖北': 0, '湖南': 0,
                    '江西': 0, '江苏': 0, '安徽': 0, '广东': 0, '海南': 0,
                    '四川': 0, '贵州': 0, '云南': 0, '香港': 0, '澳门': 0, 
                    '内蒙古': 0, '新疆': 0, '宁夏': 0, '广西': 0, '其他': 0,         
                }
for friend in my_friends:
    if friend.province in province_dict.keys():
        province_dict[friend.province] += 1
    else:
        province_dict['其他'] += 1

print(province_dict)

猜你喜欢

转载自blog.csdn.net/qq_28304097/article/details/80725612