Python Scripting: The To Do List (continued)

And they asked him, “Are you the one who is to come, or shall we look for another?” And Jesus answered them, “Go and tell John what you hear and see: the blind receive their sight and the lame walk, lepers are cleansed and the deaf hear, and the dead are raised up, and the poor have good news preached to them. Blessed is the one who is not offended by me.”

Matt 11:3-6

I'm a teacher by vocation and gifting; I love to teach. By corollary, I love to learn. I'm curious about everything and I have a blast learning about almost anything. Over the years, I've picked up quite a bit of information through the Internet. This website is my simple attempt to pay back; to contribute to the community and try to make the interwebs a better place.

As such, I don't require registration. I don't want your personal information. I don't set cookies. I won't put up advertisements. If I mention a product or service, it's because I use it, benefit from it, and I think others would too. I don't need, or want, your money. I simply want to offer some information to other curious characters.

I'm writing this site as an experiment. It's all written in a text editor. I make my own graphics, write my own JavaScript, CSS, PHP, and HTML from scratch because I'm trying to learn more about how all these pieces fit together. I use TextWrangler because I think it's a great text editor and it does everything I want in a very simple and efficient way.

If you want to contact me, try FaceBook or Twitter.

January 25, 2013

I didn't mean to leave this hanging for so long. A lot has happend since I started the To Do List; we moved to a different continent, became grandparents, started new jobs and so on. It's taken a while to get back to this, so let's get started.

In case you haven't been following along, here are all the pages leading up to this point:

We are going to add the last few functions to the script and get it set up to run. We need to add functions to delete, move and insert an item. You can just add these up toward the top of the script

def delete(num): file = open('/pathToFile/todo.txt', 'r') text = file.read() file.close list = text.split('\n') ct = len(list) file = open('/pathToFile/todo.txt', 'w') for l in range(0, num-1): file.write(list[l]) if not(num == ct and l == num-2): file.write('\n') for l in range(num, ct): file.write(str(l) + ' - ' + list[l][list[l].find('-')+2:]) if (l < ct-1): file.write('\n') file.close

This just opens the file, reads it in, finds the number passed in as an argument (the item number you want to delete), and leaves it out when it writes the file back to the disk. When it returns to the menu, the file gets renumbered. Move and insert are simliar so I will just add those in here and leave it for an exercise for the reader to figure out how it works.

def insert(num, item): file = open('/pathToFile/todo.txt', 'r') text = file.read() file.close list = text.split('\n') ct = len(list) file = open('/pathToFile/todo.txt', 'w') for l in range(0, num-1): file.write(list[l] + '\n') file.write(str(num) + ' - ' + item + '\n') for l in range(num, ct): file.write(str(l+1) + ' - ' + list[l-1][list[l-1].find('-')+2:] + '\n') file.write(str(ct+1) + ' - ' + list[ct-1][list[ct-1].find('-')+2:]) file.close def move(num1, num2): file = open('/pathToFile/todo.txt', 'r') text = file.read() file.close list = text.split('\n') ct = len(list) temp = list.pop(num1-1) # pick off the right one from the list: num1-1 save it to a temp variable list.insert(num2-1, temp) # insert it in the list at the new place: num2-1 file = open('/pathToFile/todo.txt', 'w') for l in range(ct): file.write(str(l+1) + ' - ' + list[l][list[l].find('-')+2:]) if l != ct-1: file.write('\n') file.close

That's all there is to the script. Change the permissions so the file will run and you're good to go. I've been using the script in this form for over a year now and I'm very happy with it. I hope it works for you too.

Update: I made some modifications to the original script and I've cleaned up the code a bit so it is a little more efficient. I'll outline some of the additional features below, but if you just want to download the script in it's present form just go to the downloads section and you will find it there.

I added the feature that if you want the to do item to show up on a certain day in the future the script will now do that. For example, say I need to pay a bill next Thursday, I simply invoke QuickSilver and type ". a 'pay bill' Thurs" and press enter. The "." tells QS that I want to type some text and the default text action is my todo.py script. The "a" tells todo to add; anything in quotes is the todo item; and the Thurs (actually you only need TH) tells todo to put it on the list next Thursday. When next Thursday rolls around, "pay bill" will pop up on my to do list. Besides the days of the week other options are xxd, xxw, xxm (xx is a number) for a number of days, weeks or months in the future.


All content and graphics copyright (c) 2012-2017 Brian Dentler - all rights reserved.