emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ian Barton <lists@manor-farm.org>
To: emacs-orgmode@gnu.org
Subject: Re: My Python solution to generating unique Ids in headlines
Date: Thu, 05 Mar 2009 08:39:17 +0000	[thread overview]
Message-ID: <49AF8FB5.1040805@manor-farm.org> (raw)
In-Reply-To: <200903042320.n24NKDmD007471@mail11.syd.optusnet.com.au>

> 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

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.


      parent reply	other threads:[~2009-03-05  8:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-04 23:20 My Python solution to generating unique Ids in headlines Charles Cave
2009-03-04 23:59 ` Nick Dokos
2009-03-05  2:40   ` Charles Cave
2009-03-05  9:37     ` Carsten Dominik
2009-03-06  2:13       ` Samuel Wales
2009-03-05  8:39 ` Ian Barton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49AF8FB5.1040805@manor-farm.org \
    --to=lists@manor-farm.org \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).