Notebook Updater: Automating With Python

Last week I found myself wanting to automate some todo list maintenance. I’m keeping my todo list in a Zim wiki so I can access my notes easier. The internal links and formatting is very nice to have. Around the same time I was a bit curious about Python. I hadn’t worked with it in years, and even then I didn’t do anything significant with the language. I decided to take a couple of days to throw together a little script to take care of the menial work involved with maintaining my wiki. It’s a little kludgey, but it gets the job done. It probably isn’t very useful to anyone else, but I put it in a Gist just in case.

The work this program automates is fairly simple. It copies two sections of text from one file to another and does some minor editing of the first file. Since Zim has a small, regular syntax and stores everything in text files, this wasn’t a difficult task. As I started designing the program though, it became obvious that there was more work involved than I thought.

The Notebook Updater starts by reading two sections from the first (“Home”) text file — Schedule and Time Log. I keep all of my tasks in the Schedule section and a rough log of my time usage in Time Log. Both sections are copied to the second (“Week”) file and placed under the heading for the current day. After the data is safely stored in the Week file, the program starts modifying the data to update the Home file. The day’s completed tasks are removed and tomorrow’s tasks appended to the list. Then the Time Log section is cleared and the job is done.

Since this was such a small project it did not need any classes. I wrote tests using unittest for each function and tested the general operation of the program on some test data files.

This design worked out well, but there were some issues. When I started the project I didn’t plan as well as I could have. Some features of the program were designed on the spot as I was building. The features should have been well defined before I started working. This lack of design created led to messy code in some (read: many) areas. Even though it isn’t a huge or important project it still doesn’t feel right. Text manipulation isn’t my best subject, so I doubt the text-handling code is very efficient, but that’s probably not as important in this case.

The Notebook Updater project was a fun way to get started with Python. I learned something new and automated some menial work at the same time. Writing code for yourself really is a great way to learn.

You can find the Notebook Updater code here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s