#coding=utf8
import itchat # 自动回复
# 封装好的装饰器,当接收到的消息是Text,即文字消息
@itchat.msg_register('Text')
def text_reply(msg):
# 当消息不是由自己发出的时候
if not msg['FromUserName'] == myUserName:
# 发送一条提示给文件助手
itchat.send_msg(u"[%s]收到好友@%s 的信息:%s\n" %
(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(msg['CreateTime'])),
msg['User']['NickName'],
msg['Text']), 'filehelper')
# 回复给好友
return u'[自动回复]您好,我现在有事不在,一会再和您联系。\n已经收到您的的信息:%s\n' % (msg['Text']) if __name__ == '__main__':
itchat.auto_login() # 获取自己的UserName
myUserName = itchat.get_friends(update=True)[0]["UserName"]
itchat.run()

好友签名标签云

# coding:utf-8
import itchat
import re itchat.login()
friends = itchat.get_friends(update=True)[0:]
tList = []
for i in friends:
signature = i["Signature"].replace(" ", "").replace("span", "").replace("class", "").replace("emoji", "")
rep = re.compile("1f\d.+")
signature = rep.sub("", signature)
tList.append(signature) # 拼接字符串
text = "".join(tList) # jieba分词
import jieba
wordlist_jieba = jieba.cut(text, cut_all=True)
wl_space_split = " ".join(wordlist_jieba) # wordcloud词云
import matplotlib.pyplot as plt
from wordcloud import WordCloud, ImageColorGenerator
import os
import numpy as np
import PIL.Image as Image d = os.path.dirname(__file__)
# 更改目录下Wordcloud生成图片,如:xiaohuangren.jpg
alice_coloring = np.array(Image.open(os.path.join(d, "xiaohuangren.jpg")))
# win系统需要更改font路径,如:C:\Windows\Fonts\msyhbd.ttc
my_wordcloud = WordCloud(background_color="white", max_words=2000, mask=alice_coloring,
max_font_size=40, random_state=42,
font_path='/Users/sebastian/Library/Fonts/Arial Unicode.ttf')\
.generate(wl_space_split) image_colors = ImageColorGenerator(alice_coloring)
plt.imshow(my_wordcloud.recolor(color_func=image_colors))
plt.imshow(my_wordcloud)
plt.axis("off")
plt.show() # 保存图片 并发送到手机
my_wordcloud.to_file(os.path.join(d, "wechat_cloud.png"))
itchat.send_image("wechat_cloud.png", 'filehelper')
# coding:utf-8
import itchat
'''
微信好友性别比例
''' # 先登录
itchat.login() # 获取好友列表
friends = itchat.get_friends(update=True)[0:] # 初始化计数器,有男有女,当然,有些人是不填的
male = female = other = 0 # 遍历这个列表,列表里第一位是自己,所以从"自己"之后开始计算
# 1表示男性,2女性
for i in friends[1:]:
sex = i["Sex"]
if sex == 1:
male += 1
elif sex == 2:
female += 1
else:
other += 1 # 总数算上,好计算比例啊~
total = len(friends[1:]) # 好了,打印结果
print u"男性好友:%.2f%%" % (float(male) / total * 100)
print u"女性好友:%.2f%%" % (float(female) / total * 100)
print u"未填性别:%.2f%%" % (float(other) / total * 100) # 使用echarts,加上这段
from echarts import Echart, Legend, Pie chart = Echart(u'%s的微信好友性别比例' % (friends[0]['NickName']), 'from WeChat')
chart.use(Pie('WeChat',
[{'value': male, 'name': u'男性 %.2f%%' % (float(male) / total * 100)},
{'value': female, 'name': u'女性 %.2f%%' % (float(female) / total * 100)},
{'value': other, 'name': u'其他 %.2f%%' % (float(other) / total * 100)}],
radius=["50%", "70%"]))
chart.use(Legend(["male", "female", "other"]))
del chart.json["xAxis"]
del chart.json["yAxis"]
chart.plot()

自动回复机器人

import requests
import itchat KEY = 'd364bd41d25c4c1a9dfcecccf8ed8494' def get_response(msg):
apiUrl = 'http://www.tuling123.com/openapi/api'
data = {
'key' : KEY,
'info' : msg,
'userid' : 'wechat-robot',
}
try:
r = requests.post(apiUrl, data=data).json()
return r.get('text')
except Exception as e:
print(e) @itchat.msg_register(['Map', 'Card', 'Note', 'Sharing', 'Picture','Text'])
def tuling_reply(msg):
defaultReply = 'I received: ' + msg['Text']
reply = get_response(msg['Text'])
return reply or defaultReply itchat.auto_login(hotReload=True)
itchat.run()

itchat 微信的使用的更多相关文章

  1. Python3 itchat微信获取好友、公众号、群聊的基础信息

    Python3 itchat微信获取好友.公众号.群聊的基础信息 一.简介 安装 itchat pip install itchat 使用个人微信的过程当中主要有三种账号需要获取,分别为: 好友 公众 ...

  2. python itchat 微信开发

    使用itchat可以简单操作微信,进行好友和群消息的发送 安装: pip install itchat 使用: import itchat, time # 登录 itchat.auto_login(h ...

  3. 利用Python统计微信联系人男女比例以及简单的地区分布

    寒暄的话不多说,直接进入主题. 运行效果图: [准备环境] Python版本:v3.5及其以上 开发工具:随意,此处使用Pycharm [依赖包] 1.itchat (CMD运行:pip instal ...

  4. python+爬虫+微信机器人 打造属于你的网购价格监督利器

    写在最前 程序是为人类服务的,最近正好身边小伙伴们在做球衣生意,当然是去nikenba专区购买了,可是有些热门球衣发布几分钟就被抢完,有些折扣球衣也是很快就被抢售一空,那么我们只能靠自己的眼睛一直盯着 ...

  5. 利用python进行微信好友分析

    欢迎python爱好者加入:学习交流群 667279387 本文主要利用python对个人微信好友进行分析并把结果输出到一个html文档当中,主要用到的python包为itchat,pandas,py ...

  6. itchat的使用

    python 微信接口 -- itchat 文档 发表于 2018-03-16 | 分类于 Python | itchat 一. 安装 $ pip install itchat 特殊的字典使用方式通过 ...

  7. python发送微信及企业微信消息

    1.发送微信消息 直接使用第三方库 itchat,其文档中有详细使用方式:https://itchat.readthedocs.io/zh/latest/ 如下实例为 发送群聊信息 # -*- cod ...

  8. 你的网购价格监督利器——python+爬虫+微信机器人

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:风,又奈何 PS:如有需要Python学习资料的小伙伴可以加点击下方链 ...

  9. 4-20模块 序列化模块 hashlib模块

    1,模块,py文件就是模块,py之所以好用就是模块多. 2,模块的分类: 1,内置模块,python 安装时自带的模块 2,扩展模块,别人写好的,需要安装之后,可以直接使用.itchat微信模块, b ...

随机推荐

  1. 「拆小鹤」使用 python 实现 QQ机器人服务。

    使用的是python的qqbot机器人库,我其实只是实现了这个库的一个插件. 具体的说明,我觉得qqbot的官方文档,还有我的插件的注释都写得很详细了,可以直接看.所以有空再写吧. 没错我就是懒..

  2. 第二篇:使用Spark对MovieLens的特征进行提取

    前言 在对数据进行了初步探索后,想必读者对MovieLens数据集有了感性认识.而在数据挖掘/推荐引擎运行前,往往需要对数据预处理.预处理的重要性不言而喻,甚至比数据挖掘/推荐系统本身还重要. 然而完 ...

  3. 【BZOJ4566】找相同字符(后缀数组)

    [BZOJ4566]找相同字符(后缀数组) 题面 BZOJ 题解 后缀数组的做法,应该不是很难想 首先看到两个不同的串,当然是接在一起求\(SA,height\) 那么,考虑一下暴力 在两个串各枚举一 ...

  4. 【BZOJ2333】棘手的操作(左偏树,STL)

    [BZOJ2333]棘手的操作(左偏树,STL) 题面 BZOJ上看把... 题解 正如这题的题号 我只能\(2333\) 神TM棘手的题目... 前面的单点/联通块操作 很显然是一个左偏树+标记 ( ...

  5. 【CJOJ1644】【洛谷2758】编辑距离

    题面 题目描述 设A和B是两个字符串.我们要用最少的字符操作次数,将字符串A转换为字符串B.这里所说的字符操作共有三种: 1.删除一个字符: 2.插入一个字符: 3.将一个字符改为另一个字符: 皆为小 ...

  6. 漫谈PID——实现与调参

    闲话: 作为一个控制专业的学生,说起PID,真是让我又爱又恨.甚至有时候会觉得我可能这辈子都学不会pid了,但是经过一段时间的反复琢磨,pid也不是很复杂.所以在看懂pid的基础上,写下这篇文章,方便 ...

  7. 怎么用secureCRT连接Linux

    首先要安装linux,参看:http://www.cnblogs.com/shenjieblog/p/5061282.html 然后要安装secureCRT,参看:http://www.cnblogs ...

  8. CMake 条件判断

    CMake简介 CMake 是做什么的? CMake是一套类似于automake的跨平台辅助项目编译的工具. 我觉得语法更加简单易用. CMake的工作流程 CMake处理顶级目录的CMakeList ...

  9. Readiness 探测 - 每天5分钟玩转 Docker 容器技术(144)

    除了 Liveness 探测,Kubernetes Health Check 机制还包括 Readiness 探测. 用户通过 Liveness 探测可以告诉 Kubernetes 什么时候通过重启容 ...

  10. EOS 开发进展速报

    Daniel Larimer 刚刚披露了 EOS 的最近开发进展,原文 :https://steemit.com/eos/@dan/ukoxz-eos-io-development-update 为了 ...