Behind AI #10: Automate 4 Boring Tasks in Python with 5 Lines of Code
Automation scripts with a few lines of Python code.
Think of the most boring task youâve ever done at work. Chances are, you can automate it with Python.
You only need to open your favorite text editor and start writing code. However, you might struggle to automate some tasks more than others and end up wasting more time.
What most people donât know, however, is that there are less-known libraries that take care of the hardest part of the automation, so you only need to write a few lines of code to get the job done.
Below are 4 tasks that you can automate with Python in 5 minutes or less. Youâll need to write 5 lines of code or so to automate each of them (seriously).
1. Sending Messages on WhatsApp
The easiest way to send messages on WhatsApp in Python is using a library called pywhatkit
.
First, we need to install it, so open up a terminal and run the following command (if possible, install it in a new virtual environment).
pip install pywhatkit
The installation might take a minute, but, donât worry, writing the script to send the message would take less.
Note: You need to log in to your WhatsApp account through WhatsApp Web before working with this library. If youâre not logged in, you wonât be able to send messages with pywhatkit
. Also, I donât recommend you to use this library in case you need to send a message that needs to remain private.
Now itâs time to send the message. We can send a message to a WhatsApp contact using the code below.
import pywhatkit
# syntax: phone number with country code, message, hour and minutes
pywhatkit.sendwhatmsg('+1xxxxxxxx', 'Message 1', 18, 52)
Keep in mind that the â18â and â52â are the hour/minute your message is being scheduled, so try to set it within 1 or 2 minutes to see the results faster.
Once you run the code, youâll get this message:
In 5 seconds, web.WhatsApp.com will open, and after 15 seconds, a message will be delivered by Whatsapp.
2. Multiple Folder Creation
Keep reading with a 7-day free trial
Subscribe to Artificial Corner to keep reading this post and get 7 days of free access to the full post archives.