Skip to content


A biophysicist teaches himself how to code

I’m a fan of Conky, a system monitor tool that can put all manner of things on your desktop. I also realized that with the number of things going on, I needed to move beyond post-it notes with scribbled cryptography regarding the things I needed to do every day. I decided to write a little code that would do (more or less) what I wanted.

As of now it’s very simple. I use a python script to both add and extract entries from a sqlite database. The extraction is written to a text file which is parsed by conky. As of now there are a lot of features that aren’t included, but this architecture should allow them to be added later if I decide I want them.

Setting up the database is a breeze. To create a table with a two columns (task and date added) you can run the following from the terminal:

$ sqlite tasks.db
sqlite>create table task_list(task varchar(100), added_on date);

Now we need some python to interface with the database:

#!/usr/bin/env python

import sys
from pysqlite2 import dbapi2 as sqlite

# Creating a new task
newtask = raw_input('What do you need to do? >> ')
t = (newtask,)

connection = sqlite.connect('tasks.db')
cursor = connection.cursor()
cursor.execute('insert into task_list values (?, date("now"))', t)

# Write today's tasks
cursor.execute('select * from task_list where added_on=date("now")')

for row in cursor:
    todaystasks.append('> '+row[0]+'\n')

output = open('todaystasks.txt', 'w')    


The key lines in this code are 13 (adds a task to the database) and 17 (gets today’s tasks from the database). Like I said at the top, this is a really sloppy code for several reasons. The main one is that every time we add a task, it does the extraction and output of the text file. The performance isn’t an issue at this time and I was too lazy to write it out nicely here, but it’s probably one of the first things I’ll fix. Secondly, it just pulls out the tasks that were added today. The older ones are still left in the database but never accessed. This was an intentional lapse, as I plan on adding the ability to carry over unfinished tasks from one day to another. Anyhow, it gets the job done for now.

Finally we just need the conky bit. I’ll leave it up to you to define most of the conky file, but somewhere under the TEXT line you can add something like this:

${font MyriadPro-Regular:size=13}Today's Tasks:
${execi 600 cat /home/jason/scripts/todaystasks.txt | fold -w40 }

For my purposes I put this in its own file called ~/.conkytasks and call it with conky -d -c ~/.conkytasks &
This updates the task list every 5 minutes and wraps it at 40 characters.


Tags: , ,

%d bloggers like this: