This project is the relevant code for the live video of the laboratory course "Using WeChat API to Turn Your WeChat into a Chatbot". During the live broadcast, we implemented a simple WeChat robot based on the itchat software package, which was connected to Turing robot, Xiaodou robot, and simple system monitoring functions.
Course address https://www.shiyanlou.com/courses/684
Live video playback address http://www.bilibili.com/video/av12860627/
renderings
If we can simulate WeChat login and receive WeChat messages, we can analyze and process these messages and respond accordingly. This is the basic principle of WeChat chat robot.
To put it simply, I can simulate logging into WeChat account A through itchat. After the account is logged in successfully, I can use other WeChat accounts to send messages to account A, and then I can see the effect of the chatbot.
The WeChat robot implemented in this project is not only connected to the Xiaodou robot, but also implements simple system monitoring functions. System performance data collection is implemented based on the package psutil.
After installing the Python execution environment, you can install the virtualenv
software package through the pip
command, and then build the execution link based on the package. Start this project with the following steps:
# 创建工作目录
$ mkdir ~/project
$ cd ~/project
# 克隆本项目
$ git clone https://github.com/aiden0z/wx_robot_example.git wx_robot
$ cd wx_robot
# 安装 virutalenv 软件包,如果已经安装,可以跳过该操作
$ sudo pip install virtualenv
# 创建 virtualenv 环境
$ virtualenv env
# 激活 virtualenv 环境
$ source env/bin/activate
# 安装项目依赖包
$ pip install -r requirements.txt
# 启动机器人
$ python robot.py
In the above steps, the behavior starting with #
is a comment, and the behavior starting with $
is the actual command that needs to be executed. The requirements.txt
contains all the dependency packages of this project. After the project is started successfully, you can see effects similar to the following:
$ python wx_robot.py
Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
Then scan the QR code to log in, and use WeChat friends to send messages, and you can see the effect.
If you have any questions, you can ask them in the lab building discussion area, or open an issue in this project.
For more exciting courses, you can go to the laboratory building to study.