Re: [Orgmode] My Python solution to generating unique Ids in headlines
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. ___ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[Orgmode] My Python solution to generating unique Ids in headlines
Recently I asked about a method of inserting a unique number in a headline. My requirement is to be able to uniquely identify a particular headline when exporting data to another system (ListPro on Palm/Windows). 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 3. I created a one line batch file nextnum.bat (I'm on Windows!) containing: python c:/charles/gtd/next_todo.py 4. In org-mode I insert the unique id by positioning the cursor at the end of the headline text, then entering the command ESC-1 ESC-! nextnum RET Ctl-D The Ctrl D is needed to remove a carriage return (not sure why it is there. Can someone give me Lisp code equivalent of the command sequene above? I know it is something to do with (shell command ) The end result now looks like *** Post to org-mode list about next sequential [#315] :COMPUTER: Once I have Lisp code to implement the command sequence I will have a satisfactory solution to generating the unique id when I need it. --- Charles Cave Sydney, NSW, Australia Email: charles_c...@optusnet.com.au Follow me on Twitter: www.twitter.com/ozcaveman --- ___ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode
Re: [Orgmode] My Python solution to generating unique Ids in headlines
Charles Cave charles_c...@optusnet.com.au wrote: ... print [#%s] % val ... ESC-1 ESC-! nextnum RET Ctl-D The Ctrl D is needed to remove a carriage return (not sure why it is there. Try import sys sys.stdout.write([%d] % val) instead of print. It should work on Windows as well (but I have not tested it there). Can someone give me Lisp code equivalent of the command sequene above? I know it is something to do with (shell command ) (shell-command nextnum t) It may be necessary to specify a complete path to the command. The end result now looks like *** Post to org-mode list about next sequential [#315] :COMPUTER: Once I have Lisp code to implement the command sequence I will have a satisfactory solution to generating the unique id when I need it. But I still don't understand why you need an external program: what is wrong with (insert (format [%s] (org-id-new)))? Are the IDs too ugly or is there some other problem? The trouble with unique IDs in files is that it's easy for them to get out of sync (leading to non-uniqueness), e.g. if there are two processes trying to get a unique id at the same time. Nick ___ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode