#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. js运算符单竖杠“|”的用法和作用及js数据处理

    js运算符单竖杠“|”的作用 很多朋友都对双竖杠“||”,了如指掌,因为这个经常用到.但是大家知道单竖杠吗?今天有个网友QQ问我,我的 javascript实用技巧,js小知识 , 这篇文章里面,js ...

  2. Keras常见问题及解答

    Keras官方中文版文档 如何引用 Keras? 如何在 GPU 上运行 Keras? 如何在多 GPU 上运行 Keras 模型? "sample", "batch&q ...

  3. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  4. 【BZOJ4869】相逢是问候(线段树,欧拉定理)

    [BZOJ4869]相逢是问候(线段树,欧拉定理) 题面 BZOJ 题解 根据欧拉定理递归计算(类似上帝与集合的正确用法) 所以我们可以用线段树维护区间最少的被更新的多少次 如果超过了\(\varph ...

  5. 【BZOJ1001】狼抓兔子(网络流)

    [BZOJ1001]狼抓兔子(网络流) 题面 Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还比较笨, ...

  6. 【CJOJ1090】【洛谷1967】【NOIP2013】货车运输

    题面 Description A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物,司机们想知道每辆车在不超过车辆 ...

  7. JAVA面试一

    ORACLE分页 -- 要求根据年龄排序后的 第三 行到第6 行的数据 (?) 分页语句 select t.* from ( select t1. *, rownum num from ( selec ...

  8. 基于synchronized实现的阻塞队列

    package com.lilei.pack09; import java.util.concurrent.ExecutorService; import java.util.concurrent.E ...

  9. 常见的if语句shell脚本

    常见的if语句shell脚本 author :headsen  chen  2017-10-17  15:00:07 1,cat if.sh 2, cat  if2.sh

  10. 第一迭代目标——future weather

    第一个迭代目标(主要数据) 引导界面.获取天气数据(api接口).天气分享 人员工作分配: 引导界面:周子静,界面的引导,耗时3天 获取天气数据:包舒婷.俞先浩,api接口,耗时5天 天气分享:郭磊蕾 ...