So I’m going to get a little personal with this post. I’ve been having fun getting more into Python and found a great use case for a pet project. By the way, two Python posts in a row?!? Hack all the things! Ok, my lovely wife has a bad habit which I just don’t understand. She doesn’t like drinking water and forgets to do it. I know, right! Very strange. I drink water constantly so it’s very foreign concept to me.
In order to help her out, I decided to write a program to remind her to drink water. The best way to do this was to send her a text message. There’s a fantastic service called Twilio that provides messaging capabilities. If you’ve ever ordered an Uber, you’ve gotten a text via Twilio. So I created an account and got an API key (free) and my own Twilio phone number ($1). You can do testing for free though.
Next, I installed Twilio’s Python library on my machine. Their library makes its super simple to write programs. I’m using python 2.7.10 so I simply installed with pip.
Check out Twilio’s API libraries here for your desired language. After reviewing Twilio’s documentation, I was able to quickly send myself a test text message. Now I just needed to script out what I’d like to send to my wife. I created a Python List that contains the messages and the program will randomly select an item from that list to text her. I keep adding to this list as I think of new witty comments.
You can view the full code on my GitHub page.
So how is this automated you may ask? Every Windows machine has a Task Scheduler. You can create your own tasks and assign the schedule desired. I created a task that launches Python and executes the .py file for this program every two hours. Yes, it only runs when my computer is on. The code also checks for day of week and time of day so it will execute a text message if it is Monday – Friday, between 10am and 5 pm. When we’re at home, I can just verbally remind her to drink water.
This was a very fun project and even was well received when my wife Facebooked about it. It got many Likes and even other users who were interested in the same. Perhaps I can take this even further and offer it as a full-fledged app. Looking forward to more code adventures!