I Made A Python Bot To Send "Good Night" Texts To My GF - by Pythonians - Medium PDF
I Made A Python Bot To Send "Good Night" Texts To My GF - by Pythonians - Medium PDF
22, 14:39 I Made a Python Bot to Send “Good Night” Texts to My GF | by Pythonians | Medium
Pythonians Follow
Save
https://pythonians.medium.com/i-made-a-python-bot-to-send-good-night-texts-to-my-gf-7c290273a01a 1/7
18.09.22, 14:39 I Made a Python Bot to Send “Good Night” Texts to My GF | by Pythonians | Medium
have to take care of her and her needs all the time, and most importantly, if she is clingy,
you have to send “Good night” texts every single night.
But I sit down to code after dinner and honestly, opening WhatsApp to text someone
after that is very distracting. I mean, I gotta take care of hundreds of methods and classes
in 3 different windows. WhatsApp web works without having the internet-connected
nowadays, but one more tab on Chrome is a big jab at my poor RAM.
So, I thought about automating the whole process to give myself some relief. Yeah, I
know, you’re going to call me a bad boyfriend, but I just made sending a boring good-
night text so damn cool. I coded a bot to do it for me!
So, let’s see how I did it. Thank me later (after reading this article, by buying me a coffee
maybe).
Backstory:
I needed to send some promotional messages to some of my colleagues some months
back. But sending the same text to everyone by copy-pasting in everyone’s chat is so
tedious and time-consuming. Plus doing it for a thousand people is just obnoxiously
repetitive.
Yes, there are other python packages to do similar things, but honestly, they suck. Every
one of those packages opens up an ugly Chrome window and then does the job. If I
minimize the window, the process fails. I wanted something that works in the
background.
So, I coded AutoWhatsPy, a package to automate your WhatsApp, that works in the
background (opens no ugly window).
You can just assign a task to a program written using the package, and it will work in the
background. Technically it does open a browser window but it doesn’t open in the
foreground. You can keep doing other things on your PC while it works in the
background. Plus a headless firefox browser window
https://pythonians.medium.com/i-made-a-python-bot-to-send-good-night-texts-to-my-gf-7c290273a01a 2/7
18.09.22, 14:39 I Made a Python Bot to Send “Good Night” Texts to My GF | by Pythonians | Medium
Plus, it is completely safe to use. I made the whole project open-source so that you can
To make Medium work, we log user data.
Open in app Get started
see what the code does by yourself. The package
By using Medium, isour
you agree to completely built with python using
Privacy Policy, including cookie policy.
selenium and Firefox gechodriver.
Installing AutoWhatsPy
Environment Setup
AutoWhatsPy requires Python 3.5 (Python 3.9 will be the best option) or above to run. I
have tested it with Python 3.5. Make sure that you have Python added to your PATH.
When you install Python in your Windows system, make sure to check ‘Add Python 3.x
to PATH’. If you forget to do it, see this tutorial to know how to add Python to your
PATH for Windows.
Install Python
For Windows and Mac
Download Python 3.9 from here. Use the installer to install Python in your System.
Download ‘macOS 64-bit universal2 installer’ for Mac OS. Download ‘Windows x86–
64 executable installer’ for your Windows 64 Bit system and ‘Windows x86 executable
installer’ for Windows 32 bit system.
For Linux
Use the following command to install Python 3.9 on your Linux system.
Check pip
Make sure you have pip installed in your system. Use the following command to check if
you have pip installed.
pip --version
If you see a message like ‘pip 21.2.2’ then you have pip installed on your system.
Otherwise, follow this tutorial to install pip in your system. Generally, Python comes
https://pythonians.medium.com/i-made-a-python-bot-to-send-good-night-texts-to-my-gf-7c290273a01a 3/7
18.09.22, 14:39 I Made a Python Bot to Send “Good Night” Texts to My GF | by Pythonians | Medium
Download Package
Open up your terminal/cmd and install it1Kusing the37pip command.
Programming
Now comes the programming part. To send a single text or image (or both) message to
single/multiple contacts through WhatsApp, we have to use the message_to_contacts
function from the package. Here’s the function and the arguments needed.
Arguments
msg — Path to the text file containing the message text.
I created a file names goodnight.txt that contains just one line saying “Good night, babe”. The
content of the file looks like this:
In this case, it just contained the name of her contact name. The content of the file contacts.txt looks
like this:
Bae II
https://pythonians.medium.com/i-made-a-python-bot-to-send-good-night-texts-to-my-gf-7c290273a01a 4/7
18.09.22, 14:39 I Made a Python Bot to Send “Good Night” Texts to My GF | by Pythonians | Medium
The names in the text file should be exactly the same as they are saved on your phone. You must be
To make Medium work, we log user data.
Open in app Get started
already talking to them on WhatsApp.
By using Medium, you agree to our
Privacy Policy, including cookie policy.
gechodriver — Path to the gechodriver.exe file. Download the gechodriver.exe (link here) and
send the path as an argument. You may use the absolute path or the relative path based on how your
interpreter works. Make sure gechodriver.exe is in the same project folder you are working on. Or
add the folder where gechodriver.exe is located in the PATH. Otherwise, an error might occur. If you
still get an error, downgrade selenium to version 2.53.6.
gechodriver_log — Path to the text file where the logs of gechodriver will be saved. Make
sure gechodriver.log is in the same project folder you are working on. Otherwise, an error might occur.
Save it in your project directory with whatever name firefox assigns it.
image — (Optional) Path to the image/video you want to send. Make sure that it is
supported by WhatsApp and is of the permissible length.
Code
import autowhatspy
import os
import time
while True:
now = datetime.now()
current_time = now.strftime("%H%M")
if current_time == "2315":
https://pythonians.medium.com/i-made-a-python-bot-to-send-good-night-texts-to-my-gf-7c290273a01a 5/7
18.09.22, 14:39 I Made a Python Bot to Send “Good Night” Texts to My GF | by Pythonians | Medium
time.sleep(60)
else:
To make Medium work, we log user data. Get started
Open in app
By using Medium, you agree to our
time.sleep(30)
Privacy Policy, including cookie policy.
This sends her a “Good night, honey” text precisely at 11:15 PM. The code checks the
current time every 30 seconds and when the time reaches 11:15 PM, it sends the text. If
your PC runs 24/7, you can just keep this code running forever and ever and ever and
ever and ever… (until she leaves you)
Conclusion
I dunno if she found out that I was using a bot to send her texts or not, but, (SPOILER
ALERT), she broke up.
Then I also have to make a bot to flirt with another girl I like. That’s a lot of bots. Let’s
use them as much as we can before the machine revolution happens.
I’d love to hear your thoughts about this, so feel free to reach out to me in the comments
below!
— If this article helped you in any way, consider sharing it with 2 friends you care about.
THANK YOU
https://pythonians.medium.com/i-made-a-python-bot-to-send-good-night-texts-to-my-gf-7c290273a01a 6/7
18.09.22, 14:39 I Made a Python Bot to Send “Good Night” Texts to My GF | by Pythonians | Medium
Your email
Subscribe
By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our
privacy practices.
https://pythonians.medium.com/i-made-a-python-bot-to-send-good-night-texts-to-my-gf-7c290273a01a 7/7