目录

itchat

一安装itchat

pip install itchat
pip install echarts-python

二登陆并向文件传输助手发消息

```
import itchat

登录

itchat.login()

发送消息,filehelper是文件传输助手

itchat.send(u'hello', 'filehelper')

<h4 class='title'>二微信好友性别比例</h4>

获取好友列表

friends = itchat.get_friends(update=True)[0:]

print(friends)

初始化计数器,有男有女

male = female = other = 0

遍历这个列表,列表里第一位是自己,所以从“自己”之后计算

Sex中1是男士,2是女士

UserName, City, DisplayName, Province, NickName, KeyWord, RemarkName, HeadImgUrl, Alias,Sex

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("男性好友:%.2f%%"%(float(male)/total100))

print("女性好友:%.2f%%"%(float(female)/total
100))

print("其他:%.2f%%"%(float(other)/total*100))

<h4 class='title'>三微信设置自动回复</h4>

import itchat

import time

自动回复

封装好的装饰器,当接收到的消息是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()

<h4 class='title'>四好友头像拼接</h4>

import itchat

import math

import PIL.Image as PImage

import os

Img_Dir = os.path.join(os.path.dirname(file), 'img')

all_img_dir = os.path.join(os.path.dirname(os.path.dirname(file)), 'images')

itchat.auto_login()

friends = itchat.get_friends(update=True)[0:]

print('my friends====', friends)

user = friends[0]['UserName']

num = 0

for i in friends:

img = itchat.get_head_img(userName=i['UserName'])

fileImage = open(os.path.join(Img_Dir, str(num)+".png"), 'wb')

fileImage.write(img)

fileImage.close()

num+=1

ls = os.listdir(Img_Dir)

each_size = int(math.sqrt(float(640640)/len(ls)))

lines = int(640/each_size)

image = PImage.new('RGBA', (640,640))

x = 0

y = 0

for i in range(0, len(ls)+1):

try:

img = PImage.open(os.path.join(Img_Dir, str(i)+".png"))

except IOError:

print('Error')

else:

img = img.resize((each_size, each_size), PImage.ANTIALIAS)

image.paste(img, (x
each_size, y*each_size))

x += 1

if x == lines:

x = 0

y += 1

img_path = os.path.join(all_img_dir, 'all.png')

image.save(img_path)

itchat.send_image(img_path, 'filehelper')

<h4 class='title'>五微信个性签名词云</h4>

import itchat

import re

jieba分词

import jieba

wordcloud词云

from wordcloud import WordCloud, ImageColorGenerator

import matplotlib.pyplot as plt

import PIL.Image as Image

import os

import numpy as np

先登录

itchat.login()

获取好友列表

friends = itchat.get_friends(update=True)[0:]

tlist = []

for i in friends:

# 获取签名

signature1 = i['Signature'].strip().replace('span', '').replace('class','').replace('emoji','')

# 正则过滤emoji表情

rep = re.compile("1f\d.+")

signature = rep.sub('', signature1)

tlist.append(signature)

拼接字符串

text = ''.join(tlist)

jieba分词

word_list_jieba = jieba.cut(text, cut_all=True)

wl_space_split = ' '.join(word_list_jieba)

图片路径

projiect_path = os.path.dirname(os.path.dirname(file))

img_dir = os.path.join(projiect_path, 'images')

alice_coloring = np.array(Image.open(os.path.join(img_dir, 'ciyun.jpg')))

选择字体存放路径

my_wordcloud = WordCloud(

# 设置背景颜色

background_color='white',

max_words=2000,

# 词云形状

mask=alice_coloring,

# 最大字号

max_font_size=40,

random_state=42,

# 设置字体,不设置就会乱码

font_path=os.path.join(img_dir, 'simsun.ttc')

).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(img_dir, 'myciyun.png'))

itchat.send_image(os.path.join(img_dir, 'myciyun.png'), 'filehelper')

Python与微信——itchat包的更多相关文章

  1. python实现微信接口(itchat)

    python实现微信接口(itchat) 安装 sudo pip install itchat 登录 itchat.auto_login() 这种方法将会通过微信扫描二维码登录,但是这种登录的方式确实 ...

  2. python实现微信接口——itchat模块

    python实现微信接口——itchat模块 安装 sudo pip install itchat 登录 itchat.auto_login()  这种方法将会通过微信扫描二维码登录,但是这种登录的方 ...

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

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

  4. python查看微信消息撤回

    准备环境 python语言环境 python解释器-pycharm itchat介绍 itchat是一个开源的微信个人号接口,通过itchat可以实现微信(好友或微信群)的信息处理,包括文本.图片.小 ...

  5. 如何利用python制作微信好友头像照片墙?

    这个不难,主要用到itchat和pillow这2个库,其中itchat用于获取微信好友头像照片,pillow用于拼接头像生成一个照片墙,下面我简单介绍一下实现过程,代码量不多,也很好理解,实验环境wi ...

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

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

  7. Golang 微信机器人包

    一. 最近用在学习golang,写了个小工具练练手.通过golang模拟微信网页端,接收微信服务器的消息并定制.可接入图灵机器人的api实现一个微信机器人的小玩具,当然了,可以有更多更好玩的玩法. 二 ...

  8. 细数Python Flask微信公众号开发中遇到的那些坑

    最近两三个月的时间,断断续续边学边做完成了一个微信公众号页面的开发工作.这是一个快递系统,主要功能有用户管理.寄收件地址管理.用户下单,订单管理,订单查询及一些宣传页面等.本文主要细数下开发过程中遇到 ...

  9. 利用Python查看微信共同好友

    思路 首先通过itchat这个微信个人号接口扫码登录个人微信网页版,获取可以识别好友身份的数据.这里是需要分别登录两人微信的,拿到两人各自的好友信息存到列表中. 这样一来,查共同好友就转化成了查两个列 ...

随机推荐

  1. 禁止微信内的H5页面上下拖动

    客户需求:禁止微信内的H5页面上下拖动: 解决方案: 网上的答案几乎都是阻止默认事件,即: document.body.addEventListener('touchmove' , function( ...

  2. HTML5 新增的 input 事件

    以往 HTML 的 input 輸入框,無法即時反映使用者的輸入內容.onkeyup.onkeydown 事件,無法即時.精確地取得使用者的輸入資料:而 onchange.onblur 事件,要等到失 ...

  3. 从0开始的Python学习018更多的Python内容

    特殊的方法 之前学习的都是一些常用的方法,为了使我们的学习更加的完整,我们在这里学习一些特殊的方法. 一般说来,特殊的方法都被用来模仿某个行为.例如,如果你想要为你的类使用x[key]这样的索引操作( ...

  4. SQLServer创建用户登录

    创建用户登录注意事项 密码是区分大小写的. 只有创建SQL Server登录时,才支持对密码预先进行哈希运算. 如果指定MUST_CHANGE,则CHECK_EXPIRATION和 CHECK_POL ...

  5. oracle相关函数

    (大写的PS:oracle存储过程测试进不去解决方案:重新编译:) TRUNC(sysdate, 'd') + 1   ////表示今天所在周的周一的年月日,如今天是2016.04.21周四,则TRU ...

  6. 我的第一个python web开发框架(37)——职位管理功能

    对于职位管理,我们可以理解它为角色权限的管理,就像前面所说的一样,有了职位管理,后台管理系统绑定好对应的权限以后,新进员工.离职或岗位调整,管理员操作起来就非常的便捷了,只需要重新绑定对应职位就可以做 ...

  7. keil 中报错和警告提示解决办法

    1.warning: #1-D: last line of file ends without a newline 解决办法:在文件最后一行加入一个回车. 2.error: #134: expecte ...

  8. Mybatis 批量添加,批量更新

    此篇适合有一定的mybatis使用经验的人阅读. 一.批量更新 为了提升操作数据的效率,第一想到的是做批量操作,直接上批量更新代码: <update id="updateBatchMe ...

  9. Couchbase入门——环境搭建以及HelloWorld

    一.引言 NoSQL(Not Only SQL),火了很久了,一直没空研究.最近手上一个项目对Cache有一定的要求,借此机会对NoSQL入门一下.支持NoSQL的数据库系统有很多,  比如Redis ...

  10. 在Winform开发中使用Grid++报表

    之前一直使用各种报表工具,如RDLC.DevExpress套件的XtraReport报表,在之前一些随笔也有介绍,最近接触锐浪的Grid++报表,做了一些测试例子和辅助类来处理报表内容,觉得还是很不错 ...