This repository is dedicated to the study and development of Python-based
automation and most of the features are developed using the pyautogui
module.
- click, drag and drop
- screen scrolling
- insert texts
- use prompts for information and interaction with the user
- image recognition
- save a screenshot of a specific region
- create directories and interact with operating system commands
- interaction projects with online games using mouse movement, clicks and specific controls for each game
- automation project for likes and follows on Instagram
- Message automation project via WhatsApp web
- global logging configuration (config.ini) and log file
- dependencies requirements file
- error handling with
try/except
This is a Python script that automates the sending of mass messages on WhatsApp Web. Here is a brief description of the code:
-
Module Importation: The script imports several modules, including
os
,webbrowser
,pyautogui
,logging
,logging.config
,decouple.config
, andtime
. -
Logging Configuration: The script configures logging using a 'config.ini' file.
-
Function
enviar_mensagens_whatsapp_web()
: This function is responsible for sending messages on WhatsApp Web.- First, it loads the contact settings from the
.env
file. - Then, it iterates over all contacts in the
.env
file that start with 'CONTATO_'. - For each contact, it opens WhatsApp Web using the WhatsApp API URL.
- Next, it uses the
pyautogui
module to simulate clicks and typing to send the message. - If an error occurs when opening WhatsApp Web, it will be logged and an alert will be displayed.
- Finally, it waits 240 seconds before moving on to the next contact to avoid being detected as a bot.
- First, it loads the contact settings from the
-
Script Execution: If the script is run as the main script, it will call the
enviar_mensagens_whatsapp_web()
function to start the message sending process.
https://github.com/eliasalbuquerque/python-automation/blob/master/bot_whatsapp.py
Let's create a bot that determines which page it wants to follow, checks if the most recent post has not yet been liked by the bot. If a new post has been made, it should enter this post, like it, and comment something on it.
- open Instagram
- search for the page
- check if it is a follower, if not, follow
- open the most recent post
- check if the post has already been liked, if not, like
- add a comment
- return to Instagram home
- repeat process every 24h
https://github.com/eliasalbuquerque/python-automation/blob/master/rpa_instagram.py
The program has methods to:
- open a website, in this specific case, Instagram;
- mouse actions:
- move according to defined coordinates for
x
andy
, or, using the method to extract coordinates from an image; - option to only move the mouse to a point or move and click;
- move according to defined coordinates for
- scroll the site (scroll);
- follow, open the last post, like and comment, if this process has not yet been done;
- return to the home of Instagram.
- Navigate to the website https://cursoautomacao.netlify.app/
- Find and click on the field "Digite seu nome" within "exemplos Alertas" and type your name
- Click on alert, to generate the alert
- Close the alert
- Scroll the page all the way up
- Scroll down just enough to reach the section that contains the files for which you will download and click on the download button to download the excel and pdf files.
- After you have done this, create an alert that says "VOCÊ TERMINOU"
https://github.com/eliasalbuquerque/python-automation/blob/master/pyautogui_sites.py
Added to the project:
- use of functions;
- list;
- string handling from items in a list;
- error handling;
- application log;
Log:
2024-01-03 16:01:42,598 - root - INFO - START APPLICATION...
2024-01-03 16:01:42,657 - root - INFO - site aberto
2024-01-03 16:01:43,330 - root - INFO - clicou no site para ativar a janela
2024-01-03 16:01:46,434 - root - INFO - desceu ate o campo "Exemplos Alertas"
2024-01-03 16:01:47,476 - PIL.PngImagePlugin - DEBUG - STREAM b'IHDR' 16 13
2024-01-03 16:01:47,476 - PIL.PngImagePlugin - DEBUG - STREAM b'sRGB' 41 1
2024-01-03 16:01:47,476 - PIL.PngImagePlugin - DEBUG - STREAM b'gAMA' 54 4
2024-01-03 16:01:47,476 - PIL.PngImagePlugin - DEBUG - STREAM b'pHYs' 70 9
2024-01-03 16:01:47,476 - PIL.PngImagePlugin - DEBUG - STREAM b'iTXt' 91 95
2024-01-03 16:01:47,477 - PIL.PngImagePlugin - DEBUG - STREAM b'IDAT' 198 1093
2024-01-03 16:01:48,398 - root - INFO - digitou o nome no campo "Exemplos Alertas"
2024-01-03 16:01:48,429 - PIL.PngImagePlugin - DEBUG - STREAM b'IHDR' 16 13
2024-01-03 16:01:48,429 - PIL.PngImagePlugin - DEBUG - STREAM b'sRGB' 41 1
2024-01-03 16:01:48,429 - PIL.PngImagePlugin - DEBUG - STREAM b'gAMA' 54 4
2024-01-03 16:01:48,429 - PIL.PngImagePlugin - DEBUG - STREAM b'pHYs' 70 9
2024-01-03 16:01:48,429 - PIL.PngImagePlugin - DEBUG - STREAM b'iTXt' 91 93
2024-01-03 16:01:48,429 - PIL.PngImagePlugin - DEBUG - STREAM b'IDAT' 196 604
2024-01-03 16:01:49,233 - root - INFO - clicou no botao de alerta
2024-01-03 16:01:50,335 - root - INFO - fechou o alerta
2024-01-03 16:01:51,437 - root - INFO - subiu ate o inicio da pagina
2024-01-03 16:01:52,538 - root - INFO - desceu até downlods de arquivos
2024-01-03 16:01:53,567 - PIL.PngImagePlugin - DEBUG - STREAM b'IHDR' 16 13
2024-01-03 16:01:53,568 - PIL.PngImagePlugin - DEBUG - STREAM b'sRGB' 41 1
2024-01-03 16:01:53,568 - PIL.PngImagePlugin - DEBUG - STREAM b'gAMA' 54 4
2024-01-03 16:01:53,568 - PIL.PngImagePlugin - DEBUG - STREAM b'pHYs' 70 9
2024-01-03 16:01:53,568 - PIL.PngImagePlugin - DEBUG - STREAM b'iTXt' 91 93
2024-01-03 16:01:53,568 - PIL.PngImagePlugin - DEBUG - STREAM b'IDAT' 196 1194
2024-01-03 16:01:57,222 - root - INFO - downloado do arquivo excel
2024-01-03 16:01:58,263 - PIL.PngImagePlugin - DEBUG - STREAM b'IHDR' 16 13
2024-01-03 16:01:58,263 - PIL.PngImagePlugin - DEBUG - STREAM b'sRGB' 41 1
2024-01-03 16:01:58,263 - PIL.PngImagePlugin - DEBUG - STREAM b'gAMA' 54 4
2024-01-03 16:01:58,263 - PIL.PngImagePlugin - DEBUG - STREAM b'pHYs' 70 9
2024-01-03 16:01:58,263 - PIL.PngImagePlugin - DEBUG - STREAM b'iTXt' 91 93
2024-01-03 16:01:58,263 - PIL.PngImagePlugin - DEBUG - STREAM b'IDAT' 196 787
2024-01-03 16:02:01,896 - root - INFO - downloado do arquivo pdf
2024-01-03 16:02:12,654 - root - INFO - arquivos movidos para a pasta assets
2024-01-03 16:02:16,163 - root - INFO - alerta de finalizacao executado
2024-01-03 16:02:16,163 - root - INFO - END APPLICATION