|
From: | Ian Barton |
Subject: | Re: [Orgmode] My Python solution to generating unique Ids in headlines |
Date: | Thu, 05 Mar 2009 08:39:17 +0000 |
User-agent: | Thunderbird 2.0.0.19 (X11/20090105) |
I settled on using a small Python script, since I am not a Lisp programmer. 1. I created a text file todononum.txt which contains the next number to use. 2. I created the following script to read this file, return the next available number formatted in a unique, easy to find string, for example [#310].# script next_todo.py import sysnextnum_file = "C:/charles/gtd/todonum.txt" try: f = open(nextnum_file, 'r') except IOError: print "Unable to open %s. Program terminating." % nextnum_file sys.exit(1) val = int(f.readline()) + 1 f.close() of = open(nextnum_file, 'w') of.write("%d\n" % val) of.close() print "[#%s]" % val
Charles,If you don't need human readable numbers, you could try something like the following to generate a hash:
import hashlib from time import strftime timestamp = strftime("%Y-%m-%d %H:%M:%S") s = myorg_item + timestamp myhash = hashlib.sha224(s).hexdigest()This combines your org text with the current timestamp to generate a hash. Since it's unlikely that you will try to create a hash from two identical org items at the same moment in time, this should be unique.
Ian.
[Prev in Thread] | Current Thread | [Next in Thread] |