今天在外面 Coding,後面驚現美女,如何優雅的看看她呢?快速瞅一眼,用手機僞裝自拍?做爲程序員,想到的是使用 Python 遠程控制本身的電腦python
配圖與本文無關程序員
#coding=utf-8
import itchat
import os
import time
import cv2
sendMsg = "消息助手:暫時沒法回覆"
usageMsg = "使用方法:\n"\
"1.運行CMD命令:cmd xxx (xxx爲命令)\n" \
"-例如關機命令(只適合 Windows):\ncmd shutdown -s -t 0\n" \
"2.獲取當前電腦用戶:cap\n" \
"3.啓用消息助手:ast\n" \
"4.關閉消息助手:astc"
flag = 1 #消息助手打開
nowTime = time.localtime()
@itchat.msg_register('Text')
def text_reply(msg):
global flag
message = msg['Text']
fromName = msg['FromUserName']
toName = msg['ToUserName']
print("收到來自" + fromName +"的消息: \n" + message + "\n")
if toName == "filehelper":
if message == "cap":
cap = cv2.VideoCapture(0)
time.sleep(5) # 延遲5秒再讀取
ret, img = cap.read()
cv2.imwrite("weixinTemp.jpg", img)
itchat.send('@img@%s'%u'weixinTemp.jpg', 'filehelper')
cap.release()
cv2.destroyAllWindows()
if message[0:3] == "cmd":
os.system(message.strip(message[0:4]))
if message == "ast":
flag = 1
itchat.send("消息助手已開啓", "filehelper")
if message == "astc":
flag = 0
itchat.send("消息助手已關閉", "filehelper")
elif flag == 1:
print("回覆給某人: " + message + "\n")
itchat.send(sendMsg, fromName)
if __name__ == '__main__':
itchat.auto_login(hotReload=True)
itchat.send(usageMsg, "filehelper")
itchat.run()
複製代碼
$ python wechat_remote_cap.py
複製代碼
Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
複製代碼
發送 cap 消息給文件傳輸助手web
例如:發送 cmd ls 消息給文件傳輸助手windows
只適用於 Windows。Mac 的命令行不一樣,且須要加sudo,而後在終端輸入電腦密碼才行 windows 遠程關機,發如下消息給文件傳輸助手 cmd shutdown -s -t 0bash
Mac 遠程關機,發如下消息給文件傳輸助手(mac 會提示輸入電腦密碼) cmd sudo shutdown -h +2微信
本文介紹了使用 Python 遠程控制電腦的方法,主要的技術是使用了 itchat 和 opencv2。ide
歡迎掃碼關注公衆號,你們一塊兒相互交流 ui