4 Simple Python Ideas to Automate Your Workflow
Automation. It’s supposed to remove work. So, why not help it along?
Truth be told, automating even simple tasks robustly takes time and a lot of dependency management which can become very complex.
Nevertheless, it can be very rewarding to automate some simple tasks. Even if it was more for fun.
For those that are Python fans already, you know how friendly Python is for interacting with just about anything. From sending HTTP requests, interacting with APIs, to loading and managing databases.
Python is a great choice for automation.
Here are five simple things you can automate that can help your various workflows and projects.
1. Moving the Mouse Automatically So Your Skype/Lynk Shows You As Active at Work
Imagine you have been scrolling through the newsfeed of your favorite social media app for the last ten minutes. Suddenly, your Lynk active symbol turns yellow. You’re inactive and not in a meeting.
Your nosey boss comes over and taps you on the shoulder.
Surprised, you look up to see him glaring down at you. He has a bad habit of micro-managing every second of your time.
“Hey, uh, I want you to relax and all but how is that module coming along,” he asks. You grit your teeth and provide some sort of polite answer.
“Cool, well, I just want to make sure you are focusing. Janice, our VP, is really expecting us to meet our deadline.”
End of interaction.
If only Lynk didn’t call you out like that.
Wait, you can get around this. After a few moments of Googling, you find a script to move your mouse and start coding up a job to run every few minutes that will make sure your mouse is moving.
These movements of the mouse and the keyboard can help make it look like you are active at work, in the case of Skype or Lynk.
The automation movement uses Python’s PyAutoGUI module. To install the PyAutoGUI module, run the following command:
pip install pyautogui
Python controls and tracks the mouse using your screen’s coordinate system. For instance, if you use a 1920×1080 screen resolution, the coordinate system for your screen would look like this:
As you will notice, you need to get the elements you want to interact with. This is arguably one of the harder parts of creating a web-scraper or automated script that logs in to sites.
There are several ways to detect the elements of a web application to find the login fields.
Common ways of finding elements include ID (like the example above), CSS selectors, name, and XPaths.
A different approach to locating elements for the login process can be found in the official documentation of Selenium. Some websites engage more dynamic content (like several JavaScript!).
Overall, watching Selenium automatically click buttons and log in to your favorite sites is mesmerizing. Things just start moving and working without your interaction.
Almost like magic!
3. Automatic File Backup
Creating automatic backup files can be very useful if you perform regular backups.
You may be conversant with ZIP files (files with the .zip extension). ZIP files can contain several files with their compressed contents. And, as ZIP files can also hold many folders and subfolders, it becomes a handy way to backup files by packaging them into one.
A single ZIP file, called an archive file, can be created automatically using Python functions in the zipfile module.
You can also open (or extract) ZIP files using Python. The script is shared below.
This script was taken from the book Automate the Boring Stuff with Python(in case you want even more ideas).
4. Automatically Post YouTube Videos to Reddit Threads
Another one-off idea that we recently saw and thought was an interestingway of automating tasks you might do quite often, is using a script to post multiple videos to Reddit.
Posting YouTube videos in Reddit threads can also be automated. The use of PRAW, a Python wrapper that enables you to scrape data, can offer much more to your Reddit experience.
To get started, install PRAW using pip.
The script below automatically posts YouTube videos to Reddit threads.
Conclusion
Automating tasks can be a lot of fun. Watching your program automatically log in to your favorite site, or load hundreds of files into a database, can make you feel as if you have re-designed the wheel.
And, there are a lot of great libraries out there that can help you automate tasks easily. Excel reports, emails, and other tasks can be simplified in a few lines of code.
As long as it is maintainable!
If you enjoyed this video about software engineering then consider these videos as well!
Using Python To Scrape Meet-up API
The Advantages Healthcare Providers Have In Healthcare Analytics
142 Resources for Mastering Coding Interviews
Learning Data Science: Our Top 25 Data Science Courses
The Best And Only Python Tutorial You Will Ever Need To Watch
Dynamically Bulk Inserting CSV Data Into A SQL Server
4 Must Have Skills For Data Scientists
What Is A Data Scientist