Hacking Health With SendGrid and SMSSendGrid Team
I’m trying to drink more water starting today. There are several reasons behind it, but the top one is to make my mom happy. Mothers are somewhat hard to please. At least mine is…
I’ve attempted this in the past, but it didn’t end up well. In my first attempt, I had alarms set up at every single hour. This obviously didn’t work since alarms are a bit annoying. I would be in a meeting or having a conversation, and my water alarm would start ringing. Awkward…
Since I still want to accomplish this, and alarms shouldn’t step in the way of a hacker, I built a better, more simple, system. I wrote a small script that will send me an SMS using SendGrid while my own computer is on at specific hours. Now, why would it work only when your computer is on you may ask? My logic is, if my computer is on, chances are that I will be sitting in front of it and water is completely obtainable.
Lets get to the implementation of it! I first wrote my basic Python template in a file called water_reminder.py:
Notice that you can get this from the docs of the Python-Library. The one thing I want to bring up is the fact that my to address is my actual phone number’s SMS address. Yes… I use Sprint… Don’t judge me. If you run this basic script, you shall receive an SMS! SMSs over email :O For health!
Now to get a bit more complicated. Append the following line to the top of your file:
This line will let us know which Python interpreter we should use to evaluate the script. The goal is to make a script executable. To finish this process, you will need to run the following command on the file:
Now you can run the script by running the following command:
BOOM! The rest is easy as PI. We can throw this script in a cron and it will execute whenever we want it. If you don’t know how to set up a cronjob, fear not! Let’s start by typing:
This will bring up a file where you can specify the jobs that you want to run in a time basis. In my case, my file looks like this:
This basically says that I want to receive an SMS every day at 10AM, 11AM, etc. I can check why a message wasn’t delivered by checking the log in /tmp/cronlog.out.
And this is the final output! Now you can drink a lot of water like me (or set up SMS reminders for anything else you want). If you loved or hated this post, please let me know! If you have better ways, I’m all ears 🙂