Python uses itchat to control computers on mobile phones and pythonitchat

Source: Internet
Author: User
Tags sendmsg

Python uses itchat to control computers on mobile phones and pythonitchat

This article provides an example of how python uses itchat to control computers on mobile phones for your reference. The details are as follows:

1. Prepare materials

First, python must be installed on the computer, and opencv is better (not required)

If opencv is installed, find cv2.pyd In the python directory of opencv, and put the file to the python library search path to import it.

Then download itchat: github

2. Start Using

Download itchat and decompress it (we recommend that you read the docs in this folder first). Then, execute the cmd command in this folder to install the itchat Library:

python setup.py install

Then you can run the demo program:

# Encoding: utf8import itchatimport osimport time # import cv2 # If opencv is used, you can remotely take a photo. sendMsg = u "[Message assistant]: temporarily unable to reply "# automatic reply content usageMsg = u" Usage: \ n1. run CMD command: cmd xxx (xxx is the command) \ n-for example, shutdown command: \ ncmd shutdown-s-t 0 \ n2. get an image: cap \ n3. enable message Assistant (disabled by default): ast \ n4. disable message ASSISTANT: astc "@ itchat. msg_register ('text') # register the Text message def text_reply (msg ): # Heartbeat program global flag message = msg ['text'] # receive Text message fromName = msg ['fromusername'] # sender toName = msg ['tousername'] # receiver if toName = = "filehelper ": if message = "cap": # remotely take a photo and send it to your mobile phone # cap = cv2.VideoCapture (0) # ret, img = cap. read () # cv2.imwrite ("weixinTemp.jpg", img) #itchat.send('@img@ss'{u'weixintemp.jpg ', 'filehelper') # cap. release () if message [0] + message [1] + message [2] = "cmd": # remotely execute the cmd command OS. system (message. strip (message [0] + message [1] + message [2] + message [3]) # Run the cmd command remotely to shutdown if message = "ast ": flag = 1 itchat. send ("message assistant enabled", "filehelper") if message = "astc": flag = 0 itchat. send ("message assistant disabled", "filehelper") elif flag = 1: itchat. send (sendMsg, fromName) myfile. write (message) # Save the message content myfile. write ("\ n") myfile. flush () flag = 0 # message assistant switch nowTime = time. localtime () filename = str (nowTime. tm_mday) + str (nowTime. tm_hour) + str (nowTime. tm_min) + str (nowTime. tm_sec) + ". txt "myfile = open (filename, 'w') if _ name _ = '_ main _': itchat. auto_login () itchat. send (usageMsg, "filehelper") itchat. run ()

After successful execution, it will jump out of a QR code, scan the code to log on, and then you can remotely operate the computer on the mobile phone via the mobile assistant. The goal of using opencv is to achieve remote photography, the Code has been commented out in the above demo.

Others: You can use itchat to implement interesting functions such as robots. github provides more detailed instructions. If you want to start the system, you can create a task in the task plan.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.