Thursday, September 10, 2015

Is the recycling getting picked up next week?

To develop my Python skills, I have been working through the codeacademy tutorials in Python for beginners. I really think that when learning a new program, the best way to get comfortable with it is to just work on my own projects. To that end, I wrote a simple script to solve a problem I run into in my daily life with unfortunate regularity. The City of Knoxville collects trash every Monday, and recycling every other Monday. I have a terrible time remembering whether the next Monday will be recycling pick-up day or not. This script will let me know whether or not the next coming Monday is a recycling day.

The conceptual flow for this script is:

1. Pull the current date from the computer

2. Assess how many weeks it has been since 31 August 2015, a day when the recylcing was picked up.

3. Determine whether the current week is an odd week since that week that the recycling was known to be picked up, and if so, return a print out stating that this coming Monday will be recycling day. If not, it will return a different output.

This script utilizes the 'datetime' module from the Python 2.7.3 library. It was neat to see the differences and similarities between Python functions and R functions. Importing the function in Python is just like importing packages in R. I like the syntax in the module, such as in the line 'now = datetime.datetime.now()', where I call the module (the first 'datetime') and then the function (the 'datetime.now').

The code for the script can be found at:

https://gist.github.com/dwalke44/3d50b824de04e294bf9d

No comments:

Post a Comment