Python查看微信好友男女比例及地域为位置和图灵机器人自动聊天
2020-02-17 05:08
856 查看
首先在pycharm中
安装:wxpy 支持 Python 3.4-3.6,以及 2.7 版本
pip install -U wxpy
安装 pillow模块
pip install pillow
安装 pyecharts模块
pip install pyecharts
安装 pyecharts_snapshot 模块
pip install pyecharts_snapshot
安装 echarts-countries-pypkg 模块
pip3 install echarts-countries-pypkg
然后添加代码
这是查看男女比例的
from wxpy import * from pyecharts import Pie import webbrowser bot=Bot() #注意手机确认登录 friends=bot.friends() #拿到所有朋友对象,放到列表里 attr=['男朋友','女朋友','未知性别'] value=[0,0,0] for friend in friends: if friend.sex == 1: # 等于1代表男性 value[0]+=1 elif friend.sex == 2: #等于2代表女性 value[1]+=1 else: value[2]+=1 pie = Pie("朋友男女比例") pie.add("", attr, value, is_label_show=True) #图表名称str,属性名称list,属性所对应的值list,is_label_show是否现在标签 pie.render('sex.html')#生成html页面 # 打开浏览器 webbrowser.open("sex.html")
这是看地域位置的
from wxpy import * from pyecharts import Map import webbrowser bot=Bot() friends=bot.friends() area_dic={}#定义一个字典,用来存放省市以及省市人数 for friend in friends: if friend.province not in area_dic: area_dic[friend.province]=1 else: area_dic[friend.province]+=1 attr = area_dic.keys() value = area_dic.values() map = Map("好朋友们的地域分布", width=1200, height=600) map.add( "好友地域分布", attr, value, maptype='china', is_visualmap=True, #结合体VisualMap ) #is_visualmap -> bool 是否使用视觉映射组件 # map.render('area.html') webbrowser.open("area.html")
然后是图灵机器人聊天的
import json import requests from wxpy import * bot = Bot() # 调用图灵机器人API,发送消息并获得机器人的回复 def auto_reply(text): url = "http://www.tuling123.com/openapi/api" api_key = "9df516a74fc443769b233b01eqwer42" payload = { "key": api_key, "info": text, } r = requests.post(url, data=json.dumps(payload)) result = json.loads(r.content) return "[来自智能机器人] " + result["text"] @bot.register() def forward_message(msg): return auto_reply(msg.text) embed()
附上一个对方发什么消息就回什么消息的
from wxpy import * bot=Bot() @bot.register() def recv_send_msg(recv_msg): print('收到的消息:',recv_msg.text) # recv_msg.text取得文本 return '自动回复:%s' %recv_msg.text # 进入Python命令行,让程序保持运行 embed()
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- python学习笔记(一)
- Python爬虫 获取免费的代理Ip
- numpy基本操作
- python标准库 os
- PEP8 规范(python)
- python 字典
- Eclipse安装python开发插件(转)
- Python 网页使用cookie(转)
- python中文字符乱码(GB2312,GBK,GB18030相关的问题)
- python 的 集合,字典,元组,列表
- 为什么Python做小数计算不靠谱
- python语言种类特点
- python 小知识拾遗
- Python:使用EasyGUI不显示图片
- Python:python3中__bases__的使用(MRO)
- 用python的循环写九九乘法表
- python高级爬虫笔记(1)
- python高级爬虫笔记(2)
- python高级爬虫笔记(4)
- python高级爬虫笔记(3)