Automatically reply to QQ messages with Python, with source code!

Recently, I looked at the video of app automation using python and thought it was good, so I made a program with what I learned to automatically reply to QQ messages.

  1. preparation
    1.1 installing the client module
    Open the command window and enter the command:

pip install appium-python-client
1.2 installing Appium Server
Download at:

1.3 installing JDK
After installation, add the environment variable JAVA_HOME, specify the installation directory of jdk, and the minor part is:

1.4 installing android sdk
Add an environment variable ANDROID_HOME, set the value to the decompression directory of the sdk package, and the small number is:

In addition, it's better to add ADB in the path Exe environment variable

1.5 screen projection software
Xiaobian uses the same screen assistant of mizhuo. The download website is:

  1. Connect phone
    The USB connection used by Xiaobian needs a data cable to connect the mobile phone with the computer. At the same time, it needs to turn on the developer mode of the mobile phone.

So how to open the developer mode? Take Xiaobian mobile phone as an example (OPPO mobile phone) to go to the mobile phone settings, click about mobile phone, and then click the version number all the time. When the following words appear.

Then enter other settings (different mobile phones may be different), and you can see that there is an additional developer option here.

Enter the developer option and turn it on. You can find a USB debugging switch here. Turn it on.

After you open it, you can see it on this projection software python basic tutorial The picture of the mobile phone appears.

  1. Test whether the connection is successful
    In the command window, enter: adb devices -l, if the following appears: c# tutorial This picture should be successfully connected!

Sometimes, an error may be reported. The general reason is the ADB of the projection software Exe version and adb.exe version of sdk If the exe version is inconsistent, (Xiaobian guessed by himself), you should only add any ADB Just copy exe to another one.

  1. code implementation
    Reference codes are as follows:
from appium import webdriver
import time

    'appPackage':'com.tencent.qqlite',  # Automation application




print('current QQ Message is%d individual'%(len(list2)))


def send_Message(text2:str):   # Send a message
    print("send message:%s"%(text2))

"Liu Bang, Ziji, from Fengyi, Peijun county (now Fengxian County, Jiangsu Province). Outstanding statesmen, strategists and military commanders in Chinese history, the founding emperor of the Han Dynasty, and the great founders and pioneers of the Han nation and Han culture have made outstanding contributions to the development of the Han nationality and the reunification of China.",
"not yet",
"Hunan Province, abbreviated as "Xiang", is the provincial administrative region of the people's Republic of China and the provincial capital Changsha, which is bounded at 24 n°38′~30°08′,108 east longitude°47′~114°15′It is adjacent to Jiangxi in the East, Chongqing and Guizhou in the west, Guangdong and Guangxi in the South and Hubei in the north, with a total area of 21.18 10000 square kilometers."

while True:
        print('Received message:%s'%(text))      # receive messages

        if(text=='Hello, please check Liu Bang's profile for me'):
        elif(text=="Have you had lunch yet"):
        elif(text=="Introduce Hunan!"):

    except Exception as e:

Posted by scottlowe on Fri, 15 Apr 2022 03:18:38 +0930