Goodbye to Mundane Tasks - Hello to Automating your life with Python
Jonny Pabon
Posted on December 7, 2023
Wake up, sleeping giants! I know it's been a while but I'm back again with another hit for the books.
Do you wish you could clone yourself to complete the mountain of things on your to-do list? Well, Christmas has come early because Python, the scripting language, is here to help you escape towards being productive.
Imagine sipping your favorite beverage while your computer automatically checks your emails, organizes your files, and even schedules your next appointment. It may sound like something out of the movie "Her", but it's possible with the power of Python automation.
NOTE: To my neurodiverse folks, this is something I encourage you all to look into. It will make a difference in your LIFE!
But before you drop it like it's hot, let's break down the process into manageable pieces.
Let's take a walk and think of it like building a robot:
Step 1: Identify the Problem: What's the repetitive task that makes you want to scream into the void? Is it copying and pasting data, filling out forms, or maybe scheduling meetings? Once you've identified the issue, you're almost there.
Step 2: Break it Down: Imagine you're explaining the task to a five-year-old. What are the individual steps involved? Allows you to visualize the type of task you need to get the job done.
Step 3: Choose Your Tools: Python has a vast range of tools like Selenium for web scraping, Pandas for data analysis, and PyAutoGUI for keyboard and mouse control. Choose the right tools for the job and watch your worries disappear.
Step 4: Learn to Code: Hey Humans! You don't need a Ph.D. in computer science to write Python code. There is a vast variety of places to learn all of this. All you need is determination and a mindset that embraces failure as a learning opportunity. By doing so, you can train your brain to think in a completely different way and succeed.
Step 5: Test, Refine, and Repeat: Like any good learner, your Python script needs testing and refinement. Run it through its paces, fix the bugs, and make it the automation beast you know it can be.
Step 6: Sit Back and Relax: Now that your Python script is doing the tasks that you dread, you can chill out and watch it go. The world is yours at this point.
Now, let's move on to the exciting part - how to engage your engineering brain! This example will help solidify this concept.
**1. The first thing to look for is an automation tool:
There are many options available for automating bulk emails, but for this - I will be using Python with the library pyautogui
2. Identify email application elements:
This for me was the fun part as I learned all about the elements needed to automate sending bulk emails. For this, you need to locate the buttons and fields for creating and sending emails. You can then determine how the application handles addresses, attachments, etc.
3. Record or script the process:
Super Important:
Be sure to record your steps with a macro recorder or manually write code to simulate the steps. Include comments about filling the email address field with the Gmail group address and adding updates to the body.
4. Run the automation:
Finally, run the script or macro to automate sending the email. BOOM DONE!
Oh no! I haven't finished yet. Here's an actual code snippet I created to demonstrate this concept.
#Import pyautogui = Automation | time = time delays between actions
import pyautogui
import time
# Store gmail URL in the url variable
url = "https://mail.google.com/"
# Team email group address
group_address = "iamawesome@ohyeahiam.com"
# Fill in the subject line
subject = "New Idea to Share"
# Add in your description of the email
body_text = "Today, I would like to share something\n\n..."
# Open Gmail in a new tab, add a second delay, write url in the address bar, then automatically submit it.
pyautogui.hotkey('ctrl', 't')
time.sleep(1)
pyautogui.write(url)
pyautogui.press('enter')
# Give it a time to load after submission
time.sleep(5)
# Locates the compose button and then clicks it
compose_button = pyautogui.locateOnScreen("compose_button.png")
pyautogui.click(compose_button)
# Pass in the group_address variable
pyautogui.write(group_address)
# Subject text can go here
pyautogui.write(subject)
# Body text can go here
pyautogui.write(body_text)
# Once everything else is set, email is sent using send_button
send_button = pyautogui.locateOnScreen("send_button.png")
pyautogui.click(send_button)
# Quick confirmation that this script worked
print("Email Sent via Automation!")
Psssstt! Over here! Always remember that automating your life with Python isn't just about saving time, it's about making life easier for you. It's about saying bye felicia'ing (yep, I made that up) to those time-consuming tasks and hello to a more enriching workflow.
Hope this helps!
Posted on December 7, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.