[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orgmode] My Python solution to generating unique Ids in headlines

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 (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 sys
nextnum_file = "C:/charles/gtd/todonum.txt"

   f = open(nextnum_file, 'r')
except IOError:
   print "Unable to open %s. Program terminating." % nextnum_file

val = int(f.readline()) + 1

of = open(nextnum_file, 'w')
of.write("%d\n"  % val)

print "[#%s]" % val


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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]