Table of Contents
PYTHON AUTOMATION IDEAS FOR BEGINNERS WITH EXAMPLES
As a python enthusiast or as a python student you would be looking for ideas which you can automate. So in this article we are going to discuss about Python automation ideas for beginners with example. These ideas or projects are like building blocks for other advance automation projects.
Readers can continue scrolling down whereas video lovers can watch this video.
Idea 01 – Prevent Windows Screen Locks using Python Program using Python pyautogui
This is a simple python program which you can use to prevent screen locks. This can be very useful scripts in the situation when you are uploading big files and you have fear that screen will get locked and your uploads will be stopped etc.
You need to install pyautogui module in order to run this program. You can use pip to install pyautogui by running “pip install pyautogui” command. Below is the python program to achieve screen lock prevention.
import pyautogui import time while True: time.sleep(5) pyautogui.press('volumeup') pyautogui.press('volumedown')
Idea 02 – Automate Hit The Dot Game Using Python Program using Python pyautogui
Hit the dot is pretty simple program which can be played here manually. If you look at the program than there are three steps which has to be performed while playing the game:
- Identifying the checked box
- Moving your mouse position to the highlighted box
Now our aim is to automate all these three steps which can be achieved by below code:
import pyautogui import keyboard import time time.sleep(3) while keyboard.is_pressed('q') == False: # Match Highlighted Image anywhere on the screen with pyautogui.locateCenterOnScreen loc = pyautogui.locateCenterOnScreen('C:\\Users\\USER\\Documents\\dot.png') pyautogui.moveTo(loc) pyautogui.click()
We are importing three modules in this program as we will need all of them for various purposes in our code. Notice that we running an infinite loop and it only gets out of the loop if we press “q” from the keyboard.
We are using pyautogui.locateCenterOnScreen() to search for matching image on entire screen. Please note that you will have to save the image and provide the complete location of the saved image as an argument to pyautogui.locateCenterOnScreen() method. After matching the image this method will return x and y position of the center of the matched image. So once we know the location, we just want to move the mouse cursor to that location and for that we are using pyautogui.moveTo() function and passing the location as an argument.
Idea 03 – Automate Youtube Comments using Python pyautogui
We can break down this problem into following steps:
- Identify Like Button of any comment
- Move Mouse Pointed to Like Button
- Click On the Button
- Scroll Down to Move onto Next comment
Here is the code which can help us to automate all of these steps. First three steps are pretty much the same which we have followed in “Hitting the Dot” program. In order to scroll down or scroll up we can use pyautogui.scroll() method. In this method we need to specify how many clicks we want to move down or up. You can try running this program and adjust the clicks value as per your screen.
import pyautogui import keyboard import time time.sleep(3) while keyboard.is_pressed('q') == False: loc = pyautogui.locateCenterOnScreen('C:\\Users\\USER\\Documents\\like.png', region=(30,200,100,50)) pyautogui.moveTo(loc) # pyautogui.click() pyautogui.scroll(-30) time.sleep(0.05)