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!
Hello again! I’m back with a new post and this time it is about Python. I’ve dabbled in some MOOCs out there and recently completed the Introduction to Programming Nanodegree offered by Udacity. It was exciting, fun, and rewarding. I look forward to more MOOC classes in my future.
In my current role with a hotel company, I’m working with geospatial data much more than I have in the past. We have over 5000 hotels in the US and thus, perform analysis based on location. My task at hand is to join two separate data sets. One data set contains Postal Zip Codes but the other does not. The second data set does have Latitude and Longitude coordinates. So before I can join on Zip Codes, I must first populate the second data set with Zip Codes based on lat/lon values. This is where Python comes in.
After some googling, I discovered a Python library called Geocoder. This library provides geocoding services by leveraging various providers such as Google Maps, Bing, Mapquest, etc. One of its capabilities is the user can provide a lat/lon and it can return the Zip Code of that coordinate. Perfect!
So as test, I wrote the following program which submits a list of coordinates.
I have a CSV file that contains the lat/lon values. I pass this into Geocoder and it returns the Zip Code. The program prints each lat/lon and its Zip Code. Here’s a view of what it looks like when I run it in command line.
In my test script, I’m only looking up 3 coordinates and you can see, it works! Yay!! My first Python program written for something in the real world. So what is next? Well, ultimately my task involves over 100k coordinates. Google’s API caps its free offerings so if I’d like to maintain this program, it is going to cost a little money to complete. Secondly, I need to adjust the program so that it writes back to a CSV file with three columns (lat/lon/zip) instead of just printing on command line. Let me know if you can help otherwise, back to Googling and Stack Overflow I go!
My tech journey has brought me to want to learn a programming language. I’ve picked up some SQL for my professional life and really enjoyed writing queries, digging into data and solving problems. I want to learn a language that I can leverage both at work and for personal use. I did some research and decided that Python would be a great fit for my goals. As a data geek, I’ve been seeing Python used for many things I’d like to be able to do. From web scrapping, data processing, statistical analysis to even things that weren’t on my radar like web development.
So where do I start? I looked at the familiar free tools available out there. I started with Codeacademy. but I didn’t really like the format. I tried using the forum but people were just posting the solution code so I wasn’t learning much. I switched over to Udacity and began Intro to Computer Science. This is a class that is taught in Python and the ultimate goal is to build your own search engine. This project sounded fun but again I struggled with the format. The self-paced aspect had me putting it off constantly. Life happens and it became an after thought. I need deadlines.
So now comes Coursera. I spoke to colleague at work who was about to finish the Programming for Everyone (Python) class. He enjoyed to the experience so I decided to check it out. Coursera classes differ in length. But they follow a weekly schedule with deadlines. I believe this will assist me in satisfying my goal. The #PR4E class is taught by a professor at the University of Michigan, Dr. Chuck. Once you start watching the class videos, his passion for teaching and educational technology is clearly evident…and he has the tattoos to prove it. Check out his TEDx talk on MOOCs here.
MOOC stands for Massive Open Online Course. I love how technology has enabled MOOCs to grow and continue to mature. I wish these were available when I was younger and had more free time. I look forward to continue learning in my life from MOOCs.
The Programming for Everyone class started on October 6th and it runs 10 weeks long. But there is still time to join so if you’re interested, click here.
– Future Pythonista