Python使用itchat模块实现简单的微信控制电脑功能示例

yipeiwu_com5年前Python基础

本文实例讲述了Python使用itchat模块实现简单的微信控制电脑功能。分享给大家供大家参考,具体如下:

#!/usr/bin/python
#coding=UTF-8
import requests, json
import itchat
import os,time,datetime
from PIL import ImageGrab
from itchat.content import *
app_dir = r''#打开一个程序,填写exe文件的绝对路径
imgdir = r'E:\test.jpg'
def file_edit(wr_str):
  f1 = open(r'E:\downloadlog.txt','a')
  f1.write(wr_str+'\n')
  f1.close()
def pscr():#截取屏幕,保存图片到指定目录
  im = ImageGrab.grab()
  im.save(imgdir,'jpeg')
@itchat.msg_register([TEXT])
def text_reply(msg):
  if u"开始" in msg['Content']:
    itchat.send(u"收到开始指令,请稍等", msg['FromUserName'])
    file_edit(str(datetime.datetime.now()))
    time.sleep(3)
    os.startfile(app_dir)
    time.sleep(5)
    itchat.send(u"已开始", msg['FromUserName'])
  elif u'进度' in msg['Content']:
    itchat.send(u"收到指令,请稍等", msg['FromUserName'])
    pscr()
    itchat.send(u"请接收图片", msg['FromUserName'])
    itchat.send_image(imgdir.decode('utf-8'),msg['FromUserName'])
  else:
    pass
itchat.auto_login()
itchat.run()

发送其他消息

给自己发送消息只需要发出消息,不指定发送者,默认发给自己(登陆者)

itchat.send_msg('nice to meet you')

发送图片,ToUser不指定时发给自己

itchat.send_image(ImageName.decode('utf-8'),ToUser) # 发送图片

发送视频

itchat.send_video(VideoName.decode('utf-8'),ToUser) # 发送图片

发送文件

itchat.send_file(path.decode('utf-8')) # 图片(文件

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python进程与线程操作技巧总结》、《Python Socket编程技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总

希望本文所述对大家Python程序设计有所帮助。

相关文章

Python实现多线程的两种方式分析

本文实例讲述了Python实现多线程的两种方式。分享给大家供大家参考,具体如下: 目前python 提供了几种多线程实现方式 thread,threading,multithreadin...

python查询mysql中文乱码问题

问题: python2.7 查询或者插入中文数据在mysql中的时候出现中文乱码 --- 可能情况: 1.mysql数据库各项没有设置编码,默认为'latin' 2.使用MySQL.co...

放弃 Python 转向 Go语言有人给出了 9 大理由

放弃 Python 转向 Go语言有人给出了 9 大理由

转用一门新语言通常是一项大决策,尤其是当你的团队成员中只有一个使用过它时。今年 Stream 团队的主要编程语言从 Python 转向了 Go。本文解释了其背后的九大原因以及如何做好这一...

python实现在windows下操作word的方法

本文实例讲述了python实现在windows下操作word的方法。分享给大家供大家参考。具体实现方法如下: import win32com from win32com.client...

python配置文件写入过程详解

python配置文件有.conf,.ini,.txt等多种 python集成的 标准库的 ConfigParser 模块提供一套 API 来读取和操作配置文件 我的配置文件如下 [M...