[TOC] ##itchat

一安装itchat

pip install itchat pip install echarts-python

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

``` import itchat

登录

itchat.login()

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

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

二微信好友性别比例

获取好友列表

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)/total100)) print("其他:%.2f%%"%(float(other)/total*100))

三微信设置自动回复

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()

四好友头像拼接

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, (xeach_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')

五微信个性签名词云

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第三方库文件传输助手_Python与微信——itchat包相关推荐

  1. python第三方库文件传输助手_Python中的第三方模块(itchat)

    准备工作: pycharm导入第三方模块的包 1.ctrl+alt+s进入settings,选择Project下的Project Interpreter 2.点击右上角的加号,进入之后搜索qrcode ...

  2. python第三方库文件传输助手_python实现文件助手中查看微信撤回消息

    利用python实现防撤回,对方撤回的消息可在自己的微信文件传输助手中查看. 如果想变成可执行文件放在电脑中运行,可用pyinstaller将此程序打包成exe文件. pyinstaller 文件名. ...

  3. python第三方库文件传输_Python第三方库在Excel文件读写中的应用

    Python第三方库在Excel文件读写中的应用 文/刘卫华1 史婷婷2 许学添1 [摘 要]摘 要 [期刊名称]<电子技术与软件工程> [年(卷),期]2019(000)016 [总页数 ...

  4. python第三方库文件传输_慢步学习,python库文件概述,再来点第三方库文件安装的干货...

    python是一个开源项目 我们知道Python一个开源的程序设计语言.但确切的说法应该是,Python是一个开源的编程项目,而这个项目由全球开发者共同开发. 就像数学一样,全球开源,有共同的规则,有 ...

  5. python第三方库文件传输_本地 Python 代码上传到 Python 第三方库(Pypi)

    程序员对于编程都有自己的"套路",好的套路都会得到复用和 IT 界的传播.这时有一个疑问,怎样来实现呢?小编这里就准备介绍如何将自己写的 Python 包上传到 Python 官网 ...

  6. python第三方库文件传输_python3 post方式上传文件。

    import requests url = 'http://www.test.com/doFile.php' #url = 'http://www.test.com/doPost.php' #file ...

  7. python怎么安装itchat工具包_Python与微信——itchat包

    itchat 一安装itchat pip install itchat pip install echarts-python 二登陆并向文件传输助手发消息 import itchat # 登录 itc ...

  8. python下载什么版本的微信_Python与微信——itchat包

    [TOC] ##itchat 一安装itchat pip install itchat pip install echarts-python 二登陆并向文件传输助手发消息 ``` import itc ...

  9. 用于安装python第三方库的工具是_Python第三方库安装

    Python有一个全球社区:在这里,我们可以搜索Python第三方库的任何话题.PyPI的全称是Python包指数指Python包的指数.它是由PSF (Python软件基金会)和显示全球Python ...

  10. python第三方库使用文档_python 的第三方库的使用

    我们写python代码的时候往往需要用第三方的库文件,Python强大的原因就是有大量的功能各异的第三方库.因此学会如何使用第三方库很有必要. 除了python官方自带的模块外,大部分第三方库是需要先 ...

最新文章

  1. 国内外有名的安全扫描工具,你知道几个?
  2. 2021年信息系统项目管理师考试大纲
  3. 世界上最美的40个小镇,你见过多少个?
  4. 这9个人气超高的公众号,你还没关注吗?
  5. Redis是单线程为什么还那么快?
  6. 如何进行正确的EDM邮件营销
  7. 分贝噪音测试软件文件存储,手机分贝噪音测试软件
  8. 手机号、身份证格式校验
  9. 计算机考证广东省ps
  10. 照相机和眼睛成像的基本原理
  11. excel 80080005 服务器运行失败,Word 2016自动生成“错误:80080005服务器执行失败”...
  12. CVTE 后端开发面经
  13. qt构建浏览器_如何为组织构建安全的浏览器
  14. 论文笔记:MICCAI2018 Cell Detection with Star-convex Polygons
  15. SQL-Server 零基础入门教程[下]
  16. 编码(字符串) SDUT
  17. html视频做成背景图,《图解HTML》- video标签实现视频背景
  18. php+扫描条码,PHP条形码图像生成器
  19. SDL mac(event) 入门1 - 显示图像
  20. 前端面试题(附答案)完善中……

热门文章

  1. django 一个项目多个App项目搭建
  2. 怎么提高c语言编程能力,如何才能提高用C语言编程的能力
  3. 记账时,如何对开销进行分类
  4. 新建github分支
  5. 数据库mysql基本查询语句_数据库mysql基础查询语句实录
  6. .net core 上传文件到服务器
  7. TkMybatis的使用
  8. SP3485,MAX485
  9. 金融风控建模评分卡系列:机器学习特征选择方法
  10. MaxScript读取excel数据