微信自动回复小程序(有手就行)
昨天刷B站看見了個(gè)微信自動(dòng)回復(fù)小程序視頻作者是不高興就喝水視頻在這看著感覺(jué)挺有意思的我也搞個(gè)敷衍我女朋友。
安裝python3.4以上版本,并配置環(huán)境變量!!!
1.安裝依賴包
方法:在cmd中(win+R? 輸入cmd? 回車)輸入
pip install pyperclip 回車
pip install xlrd 回車
pip install pyautogui==0.9.50 回車
pip install?opencv-python?-i?https://pypi.tuna.tsinghua.edu.cn/simple 回車
pip install pillow 回車
?這幾步如果哪步?jīng)]成功,請(qǐng)自行百度 如 pip install opencv-python失敗
?差不多大概就是這樣。如果不行的話看這個(gè)文章,這個(gè)文章有答案我就從這搞好的
2.還要搞一個(gè)Excel?把每一步要操作的圖標(biāo)、區(qū)域截圖保存至本文件夾 ?png格式
?在Excel 的sheet1 中,配置每一步的指令,如指令類型1234? 對(duì)應(yīng)的內(nèi)容填截圖文件名(別用中文),指令5對(duì)應(yīng)的內(nèi)容是等待時(shí)長(zhǎng)(單位秒) 指令6對(duì)應(yīng)的內(nèi)容是滾輪滾動(dòng)的距離,正數(shù)表示向上滾,負(fù)數(shù)表示向下滾,數(shù)字大一點(diǎn),先用200和-200試試,然后保存文件就行了。
import pyautogui import time import xlrd import pyperclip#定義鼠標(biāo)事件#pyautogui庫(kù)其他用法 https://blog.csdn.net/qingfengxd1/article/details/108270159def mouseClick(clickTimes,lOrR,img,reTry):if reTry == 1:while True:location=pyautogui.locateCenterOnScreen(img,confidence=0.9)if location is not None:pyautogui.click(location.x,location.y,clicks=clickTimes,interval=0.2,duration=0.2,button=lOrR)breakprint("未找到匹配圖片,0.1秒后重試")time.sleep(0.1)elif reTry == -1:while True:location=pyautogui.locateCenterOnScreen(img,confidence=0.9)if location is not None:pyautogui.click(location.x,location.y,clicks=clickTimes,interval=0.2,duration=0.2,button=lOrR)time.sleep(0.1)elif reTry > 1:i = 1while i < reTry + 1:location=pyautogui.locateCenterOnScreen(img,confidence=0.9)if location is not None:pyautogui.click(location.x,location.y,clicks=clickTimes,interval=0.2,duration=0.2,button=lOrR)print("重復(fù)")i += 1time.sleep(0.1)# 數(shù)據(jù)檢查 # cmdType.value 1.0 左鍵單擊 2.0 左鍵雙擊 3.0 右鍵單擊 4.0 輸入 5.0 等待 6.0 滾輪 # ctype 空:0 # 字符串:1 # 數(shù)字:2 # 日期:3 # 布爾:4 # error:5 def dataCheck(sheet1):checkCmd = True#行數(shù)檢查if sheet1.nrows<2:print("沒(méi)數(shù)據(jù)啊哥")checkCmd = False#每行數(shù)據(jù)檢查i = 1while i < sheet1.nrows:# 第1列 操作類型檢查cmdType = sheet1.row(i)[0]if cmdType.ctype != 2 or (cmdType.value != 1.0 and cmdType.value != 2.0 and cmdType.value != 3.0 and cmdType.value != 4.0 and cmdType.value != 5.0 and cmdType.value != 6.0):print('第',i+1,"行,第1列數(shù)據(jù)有毛病")checkCmd = False# 第2列 內(nèi)容檢查cmdValue = sheet1.row(i)[1]# 讀圖點(diǎn)擊類型指令,內(nèi)容必須為字符串類型if cmdType.value ==1.0 or cmdType.value == 2.0 or cmdType.value == 3.0:if cmdValue.ctype != 1:print('第',i+1,"行,第2列數(shù)據(jù)有毛病")checkCmd = False# 輸入類型,內(nèi)容不能為空if cmdType.value == 4.0:if cmdValue.ctype == 0:print('第',i+1,"行,第2列數(shù)據(jù)有毛病")checkCmd = False# 等待類型,內(nèi)容必須為數(shù)字if cmdType.value == 5.0:if cmdValue.ctype != 2:print('第',i+1,"行,第2列數(shù)據(jù)有毛病")checkCmd = False# 滾輪事件,內(nèi)容必須為數(shù)字if cmdType.value == 6.0:if cmdValue.ctype != 2:print('第',i+1,"行,第2列數(shù)據(jù)有毛病")checkCmd = Falsei += 1return checkCmd#任務(wù) def mainWork(img):i = 1while i < sheet1.nrows:#取本行指令的操作類型cmdType = sheet1.row(i)[0]if cmdType.value == 1.0:#取圖片名稱img = sheet1.row(i)[1].valuereTry = 1if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:reTry = sheet1.row(i)[2].valuemouseClick(1,"left",img,reTry)print("單擊左鍵",img)#2代表雙擊左鍵elif cmdType.value == 2.0:#取圖片名稱img = sheet1.row(i)[1].value#取重試次數(shù)reTry = 1if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:reTry = sheet1.row(i)[2].valuemouseClick(2,"left",img,reTry)print("雙擊左鍵",img)#3代表右鍵elif cmdType.value == 3.0:#取圖片名稱img = sheet1.row(i)[1].value#取重試次數(shù)reTry = 1if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:reTry = sheet1.row(i)[2].valuemouseClick(1,"right",img,reTry)print("右鍵",img) #4代表輸入elif cmdType.value == 4.0:inputValue = sheet1.row(i)[1].valuepyperclip.copy(inputValue)pyautogui.hotkey('ctrl','v')time.sleep(0.5)print("輸入:",inputValue) #5代表等待elif cmdType.value == 5.0:#取圖片名稱waitTime = sheet1.row(i)[1].valuetime.sleep(waitTime)print("等待",waitTime,"秒")#6代表滾輪elif cmdType.value == 6.0:#取圖片名稱scroll = sheet1.row(i)[1].valuepyautogui.scroll(int(scroll))print("滾輪滑動(dòng)",int(scroll),"距離") i += 1if __name__ == '__main__':file = 'cmd.xls'#打開文件wb = xlrd.open_workbook(filename=file)#通過(guò)索引獲取表格sheet頁(yè)sheet1 = wb.sheet_by_index(0)print('歡迎使用不高興就喝水RPA~')#數(shù)據(jù)檢查checkCmd = dataCheck(sheet1)if checkCmd:key=input('選擇功能: 1.做一次 2.循環(huán)到死 \n')if key=='1':#循環(huán)拿出每一行指令mainWork(sheet1)elif key=='2':while True:mainWork(sheet1)time.sleep(0.1)print("等待0.1秒") else:print('輸入有誤或者已經(jīng)退出!')?
?出現(xiàn)這樣子就代表程序可以運(yùn)行了
開始程序后請(qǐng)將程序框最小化,不然程序框擋住的區(qū)域是無(wú)法識(shí)別和操作的如果程序開始后因?yàn)槟氵x擇了無(wú)限重復(fù)而鼠標(biāo)被占用停不下來(lái),alt+F4就OK了。
如何報(bào)錯(cuò)不能運(yùn)行可以看這個(gè)文章里面有解決方法!!!
OK了本期文章就到這里了喜歡的小伙伴點(diǎn)點(diǎn)免費(fèi)的贊吧,明天國(guó)慶節(jié)了祝大家國(guó)慶節(jié)快樂(lè)!!!?
總結(jié)
以上是生活随笔為你收集整理的微信自动回复小程序(有手就行)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: directx前言
- 下一篇: DataFormatString属性语法