From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Barton Subject: Re: My Python solution to generating unique Ids in headlines Date: Thu, 05 Mar 2009 08:39:17 +0000 Message-ID: <49AF8FB5.1040805@manor-farm.org> References: <200903042320.n24NKDmD007471@mail11.syd.optusnet.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lf97A-00014N-4p for emacs-orgmode@gnu.org; Thu, 05 Mar 2009 03:39:36 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lf978-00012C-Ld for emacs-orgmode@gnu.org; Thu, 05 Mar 2009 03:39:35 -0500 Received: from [199.232.76.173] (port=57857 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lf978-00011z-ED for emacs-orgmode@gnu.org; Thu, 05 Mar 2009 03:39:34 -0500 Received: from a2s22.a2hosting.com ([69.39.86.130]:54262) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Lf977-00088h-Ta for emacs-orgmode@gnu.org; Thu, 05 Mar 2009 03:39:34 -0500 Received: from [217.146.125.41] (helo=firewall.banter.local) by a2s22.a2hosting.com with esmtp (Exim 4.69) (envelope-from ) id 1Lf976-0007Wq-Jf for emacs-orgmode@gnu.org; Thu, 05 Mar 2009 03:39:32 -0500 Received: from localhost (localhost [127.0.0.1]) by firewall.banter.local (Postfix) with ESMTP id 00500C60E for ; Thu, 5 Mar 2009 08:39:30 +0000 (GMT) Received: from firewall.banter.local ([127.0.0.1]) by localhost (firewall.banter.local [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id q6kkOfcIWMz1 for ; Thu, 5 Mar 2009 08:39:17 +0000 (GMT) Received: from [192.168.0.60] (scamper.banter.local [192.168.0.60]) by firewall.banter.local (Postfix) with ESMTP id 7564EC605 for ; Thu, 5 Mar 2009 08:39:17 +0000 (GMT) In-Reply-To: <200903042320.n24NKDmD007471@mail11.syd.optusnet.com.au> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org > 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" > > 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.