当前位置:网站首页>Pyautogui realizes automatic office -rpa small case
Pyautogui realizes automatic office -rpa small case
2022-07-27 10:12:00 【User 9925864】
Today, I was chatting with a friend , He consulted a pyautogui Automatic office problem , He is a Tiktok merchant , Because if Tiktok merchants 3 If you don't reply to the customer within minutes, the store level will be reduced , So he needs a software that can automatically reply to customer information when he is resting , Before written pyautogui The basic usage of , Portal (python Office automation --pyautogui Control mouse and keyboard operation ), So I found a way to meet this requirement , Its basic principle is to automatically identify unread messages in the message list of the chat interface , Then send one during the break " Customer service is not available ", So as to bypass the reply strategy of the platform
1. install python3.4 Above version , And configure environment variables ( At present, there are clothes 3.9 Hit the pit , For my personal use 3.7.6)
course :https://www.runoob.com/python3/python3-install.html
2. Install dependency packages
Method : stay cmd in (win+R Input cmd enter ) Input
pip install pyperclip enter
pip install xlrd enter
pip install pyautogui==0.9.50 enter
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple enter
pip install pillow enter If any of these steps fails , Please Baidu Such as pip install opencv-python Failure
3. Put the icon to be operated at each step 、 Save the area screenshot to this folder png Format ( Note that if there are multiple identical icons on the same screen , Go back to the top left by default , So how to screenshot , How large area to cut , It's a learning , If the input box only cuts the blank part in the middle, it will definitely not work , The purpose is “ only ”)
4. stay cmd.xls Of sheet1 in , Configure the instructions for each step , Such as instruction type 1234 Fill in the screenshot file name for the corresponding content ( Don't use Chinese ), Instructions 5 The corresponding content is the waiting time ( Unit second ) Instructions 6 The corresponding content is the rolling distance of the roller , A positive number means roll up , A negative number means roll down , The number is bigger , First use 200 and -200 try
5. Save the file
6. double-click waterRPA.py open programs , Press 1 Express excel The instructions in are executed once , Press 2 It means to repeat the execution indefinitely until the program is closed
7. If an error is reported, it cannot be used vscode Run to see the error content ( Baidu vscode Installation and operation python Program , Error content will be reported xxxError Post the back on Baidu to search )
8. Please minimize the program box after starting the program , Otherwise, the area blocked by the program frame cannot be recognized and operated
9. If the mouse is occupied and cannot stop because you choose infinite repetition after the program starts ,alt+F4 Well ~
Those who want to develop and optimize by themselves can have a look pyautogui Library other usage
https://blog.csdn.net/qingfengxd1/article/details/108270159
Complete source code :
import pyautogui
import time
import xlrd
import pyperclip
# Define mouse events
#pyautogui Library other usage https://blog.csdn.net/qingfengxd1/article/details/108270159
def 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)
break
print(" No matching pictures found ,0.1 Try again in seconds ")
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 = 1
while 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(" repeat ")
i += 1
time.sleep(0.1)
# Data checking
# cmdType.value 1.0 Left click 2.0 Next, double-left click on 3.0 Right click 4.0 Input 5.0 wait for 6.0 Roller
# ctype empty :0
# character string :1
# Numbers :2
# date :3
# Boolean :4
# error:5
def dataCheck(sheet1):
checkCmd = True
# Row count check
if sheet1.nrows<2:
print(" No data, brother ")
checkCmd = False
# Check each row of data
i = 1
while i < sheet1.nrows:
# The first 1 Column Operation type check
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(' The first ',i+1," That's ok , The first 1 There is something wrong with the column data ")
checkCmd = False
# The first 2 Column Content check
cmdValue = sheet1.row(i)[1]
# Read the picture and click the type instruction , Content must be of type string
if cmdType.value ==1.0 or cmdType.value == 2.0 or cmdType.value == 3.0:
if cmdValue.ctype != 1:
print(' The first ',i+1," That's ok , The first 2 There is something wrong with the column data ")
checkCmd = False
# Input type , The content cannot be empty
if cmdType.value == 4.0:
if cmdValue.ctype == 0:
print(' The first ',i+1," That's ok , The first 2 There is something wrong with the column data ")
checkCmd = False
# Waiting type , Content must be numeric
if cmdType.value == 5.0:
if cmdValue.ctype != 2:
print(' The first ',i+1," That's ok , The first 2 There is something wrong with the column data ")
checkCmd = False
# Wheel event , Content must be numeric
if cmdType.value == 6.0:
if cmdValue.ctype != 2:
print(' The first ',i+1," That's ok , The first 2 There is something wrong with the column data ")
checkCmd = False
i += 1
return checkCmd
# Mission
def mainWork(img):
i = 1
while i < sheet1.nrows:
# Take the operation type of this line instruction
cmdType = sheet1.row(i)[0]
if cmdType.value == 1.0:
# Take the picture name
img = sheet1.row(i)[1].value
reTry = 1
if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:
reTry = sheet1.row(i)[2].value
mouseClick(1,"left",img,reTry)
print(" Left click ",img)
#2 Represents double clicking the left button
elif cmdType.value == 2.0:
# Take the picture name
img = sheet1.row(i)[1].value
# Number of retries
reTry = 1
if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:
reTry = sheet1.row(i)[2].value
mouseClick(2,"left",img,reTry)
print(" Double left click ",img)
#3 Right click
elif cmdType.value == 3.0:
# Take the picture name
img = sheet1.row(i)[1].value
# Number of retries
reTry = 1
if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:
reTry = sheet1.row(i)[2].value
mouseClick(1,"right",img,reTry)
print(" Right click ",img)
#4 For input
elif cmdType.value == 4.0:
inputValue = sheet1.row(i)[1].value
pyperclip.copy(inputValue)
pyautogui.hotkey('ctrl','v')
time.sleep(0.5)
print(" Input :",inputValue)
#5 For waiting
elif cmdType.value == 5.0:
# Take the picture name
waitTime = sheet1.row(i)[1].value
time.sleep(waitTime)
print(" wait for ",waitTime," second ")
#6 Stands for roller
elif cmdType.value == 6.0:
# Take the picture name
scroll = sheet1.row(i)[1].value
pyautogui.scroll(int(scroll))
print(" Roller sliding ",int(scroll)," distance ")
i += 1
if __name__ == '__main__':
file = 'cmd.xls'
# Open file
wb = xlrd.open_workbook(filename=file)
# Get tables by index sheet page
sheet1 = wb.sheet_by_index(0)
print(' Welcome to drink water if you are not happy RPA~')
# Data checking
checkCmd = dataCheck(sheet1)
if checkCmd:
key=input(' Select function : 1. Do it once 2. Cycle to death \n')
if key=='1':
# Loop out each line of instructions
mainWork(sheet1)
elif key=='2':
while True:
mainWork(sheet1)
time.sleep(0.1)
print(" wait for 0.1 second ")
else:
print(' The input is incorrect or has exited !')
边栏推荐
- Acl2021 best paper released, from ByteDance
- pytorch中对BatchNorm2d()函数的理解
- 2016 outlook
- 使用 LSM-Tree 思想基于.NET 6.0 C# 写个 KV 数据库(案例版)
- 找工作 4 个月, 面试 15 家,拿到 3 个 offer
- Understand chisel language. 26. Chisel advanced input signal processing (II) -- majority voter filtering, function abstraction and asynchronous reset
- Reason for pilot importerror: cannot import name 'pilot_ Version 'from' PIL ', how to install pilot < 7.0.0
- Intermediate and advanced test questions ": what is the implementation principle of mvcc?
- Anchor free detector: centernet
- Simple use of tflite
猜你喜欢

圆环工件毛刺(凸起)缺口(凹陷)检测案例

二叉树习题总结

视觉SLAM十四讲笔记(一):第一讲+第二讲

Food safety | the kitchen board environment is very important. Do you know these use details?

面试必备:虾皮服务端15连问
![Introduction to regular expressions of shell, general matching, special characters: ^, $,., * Character range (brackets): [], special characters: \, matching mobile phone number](/img/31/ed0d8c1a5327059f2de7493bec1c6c.png)
Introduction to regular expressions of shell, general matching, special characters: ^, $,., * Character range (brackets): [], special characters: \, matching mobile phone number

hdu5288(OO’s Sequence)

Practice and exploration of overseas site Seata of ant group

Why do microservices have to have API gateways?

Shell流程控制(重点)、if 判断、case 语句、let用法、for 循环中有for (( 初始值;循环控制条件;变量变化 ))和for 变量 in 值 1 值 2 值 3… 、while 循环
随机推荐
并发之park与unpark说明
After one year, the paper was finally accepted by the international summit
Easy to understand! Graphic go synergy principle and Practice
Fsm onehot 答题记录
Leetcode.565. array nesting____ Violent dfs- > pruning dfs- > in situ modification
3D人脸重建:Joint 3D Face Reconstruction and Dense Alignment with position Map Regression Network
C # set different text watermarks for each page of word
Understand chisel language. 23. Chisel sequential circuit (III) -- detailed explanation of chisel shift register
Anaconda installation (very detailed)
NFT系统开发-教程
Learn typescript (1)
Ant高级-task
Food safety | the more you eat junk food, the more you want to eat it? Please keep this common food calorimeter
When I went to oppo for an interview, I got numb
Leetcode.1260. 2D grid migration____ In situ violence / dimensionality reduction + direct positioning of circular array
Concurrent Park and unpark description
食品安全 | 垃圾食品越吃越想吃?这份常见食品热量表请收好
Intermediate and advanced test questions ": what is the implementation principle of mvcc?
Shell综合应用案例,归档文件、发送消息
数据库性能系列之子查询