emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-contacts from bbdb: a starting solution
@ 2011-03-08 20:51 Wes Hardaker
  2011-03-09 11:46 ` Eric S Fraga
  0 siblings, 1 reply; 4+ messages in thread
From: Wes Hardaker @ 2011-03-08 20:51 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1153 bytes --]


I finally decided to take a wack at a bbdb to org-contacts converter.
I'm attaching the file below.  It should prompt for a file and
insert all your existing bbdb records into the file using the formats
and fields that I decided was appropriate ;-)

(require 'bbdb-to-org-contacts)
M-x bbdb-to-org-contacts 

Now...  I've been using bbdb for a very very long time.  That means that
I have a lot of records.  That means that this was a good chance to find
out how well org-contacts scales.  The sad news is that it doesn't.
Once I point org-contacts at my newly generated file containing 831
records it make org-contacts really really slow down.  I wouldn't care
about the normal record searching process for just looking something up,
but it makes loading a message in gnus unusable (5 second delay per message).

So...  I need to filter down to "current ones I need to keep" or we need
to optimize the contacts a bit to cache file points where a record for a
given email address is stored or something.

-- 
Wes Hardaker                                     
My Pictures:  http://capturedonearth.com/
My Thoughts:  http://pontifications.hardakers.net/

[-- Attachment #2: bbdb-to-org-contacts.el --]
[-- Type: text/plain, Size: 2304 bytes --]

(require 'bbdb)
(require 'bbdb-com)

(defvar bbdb-to-org-contacts-record-prefix "***")

(defvar bbdb-to-org-contacts-record-blanks "   ")

(defun bbdb-to-org-contacts (to-file)
  "outputs a org-contacts file"
  (interactive (list (read-file-name "Save in file: ")))
  (let* ((filename (expand-file-name to-file))
	 (records (bbdb-records)))
    (find-file filename)
    (while records
      (bbdb-record-to-org-record (car records))
      (setq records (cdr records)))
    ))

    
(defun bbdb-record-to-org-record (record)
  "converts a single record"
  (let* (
         (name    (bbdb-record-name record))
         (company (bbdb-record-company record))
         (net     (bbdb-record-net record))
         (aka     (bbdb-record-aka record))
         (phone   (bbdb-record-phones record))
         (address (bbdb-record-addresses record))
         (notes   (bbdb-record-notes record))
	 )
    
    (insert
     (format "%s %s\n" bbdb-to-org-contacts-record-prefix name))
    (insert
     (format "%s :PROPERTIES:\n" bbdb-to-org-contacts-record-blanks))

    (when aka
      (insert
       (format "%s :AKA:\t%s\n" bbdb-to-org-contacts-record-blanks
	       (mapconcat (function (lambda(str) str)) aka ", "))))

    (when net
      (insert
       (format "%s :EMAIL:\t%s\n" bbdb-to-org-contacts-record-blanks
	       (mapconcat (function (lambda(str) str)) net " "))))

    (when company
      (insert
       (format "%s :COMPANY:\t%s\n" bbdb-to-org-contacts-record-blanks company)))

    (when phone
      (insert
       (mapconcat
	(function (lambda(rec) 
		    (if (stringp (elt rec 1))
			(format "%s :PHONE_%s:\t%s"
				bbdb-to-org-contacts-record-blanks
				(upcase (elt rec 0))
				(elt rec 1))
		      (let ((len (length rec))
			    (count 2)
			    (output (format "%d" (elt rec 1))))
			(while (< count (1- len))
			  (setq output
				(concat output
					(format "-%d"
						(elt rec count))))
			  (setq count (1+ count)))
			(format "%s :PHONE_%s:\t%s"
				bbdb-to-org-contacts-record-blanks
				(upcase (elt rec 0)) output)))))
	phone "\n"))
      (insert "\n"))

    (when notes
      (insert
       (format "%s :NOTES:\t%s\n" bbdb-to-org-contacts-record-blanks notes)))

    (insert
     (format "%s :END:\n" bbdb-to-org-contacts-record-blanks))
    ))


(provide 'bbdb-to-org-contacts)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: org-contacts from bbdb: a starting solution
  2011-03-08 20:51 org-contacts from bbdb: a starting solution Wes Hardaker
@ 2011-03-09 11:46 ` Eric S Fraga
  2011-03-09 15:18   ` Wes Hardaker
  0 siblings, 1 reply; 4+ messages in thread
From: Eric S Fraga @ 2011-03-09 11:46 UTC (permalink / raw)
  To: Wes Hardaker; +Cc: emacs-orgmode

Wes Hardaker <wjhns209@hardakers.net> writes:

> I finally decided to take a wack at a bbdb to org-contacts converter.
> I'm attaching the file below.  It should prompt for a file and
> insert all your existing bbdb records into the file using the formats
> and fields that I decided was appropriate ;-)

Thanks.  This seems to work well.  I convert >400 records and they seem
to come through fine; well, for the fields you thought appropriate, of
course...  

Are you intending to extend your code for not-so-appropriate fields?  If
so, I definitely would like to see the addresses converted and it would
be quite useful to have the notes converted entry text for the org entry
(i.e. not a property).

Thanks again,
eric
-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.4 (release_7.4.645.g3887.dirty)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: org-contacts from bbdb: a starting solution
  2011-03-09 11:46 ` Eric S Fraga
@ 2011-03-09 15:18   ` Wes Hardaker
  2011-03-10 13:07     ` Eric S Fraga
  0 siblings, 1 reply; 4+ messages in thread
From: Wes Hardaker @ 2011-03-09 15:18 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 727 bytes --]

>>>>> On Wed, 09 Mar 2011 11:46:50 +0000, Eric S Fraga <e.fraga@ucl.ac.uk> said:

ESF> Are you intending to extend your code for not-so-appropriate fields?  If
ESF> so, I definitely would like to see the addresses converted and it would
ESF> be quite useful to have the notes converted entry text for the org entry
ESF> (i.e. not a property).

I thought about trying to create a generic 'list' of matching 'this' to
'that' but hadn't gotten to it yet.

I'd be happy to change the notes so it went under the properties, if
that's what you want?  I think you want what is attached.
-- 
Wes Hardaker                                     
My Pictures:  http://capturedonearth.com/
My Thoughts:  http://pontifications.hardakers.net/

[-- Attachment #2: bbdb-to-org-contacts.el --]
[-- Type: text/plain, Size: 2298 bytes --]

(require 'bbdb)
(require 'bbdb-com)

(defvar bbdb-to-org-contacts-record-prefix "***")

(defvar bbdb-to-org-contacts-record-blanks "   ")

(defun bbdb-to-org-contacts (to-file)
  "outputs a org-contacts file"
  (interactive (list (read-file-name "Save in file: ")))
  (let* ((filename (expand-file-name to-file))
	 (records (bbdb-records)))
    (find-file filename)
    (while records
      (bbdb-record-to-org-record (car records))
      (setq records (cdr records)))
    ))

    
(defun bbdb-record-to-org-record (record)
  "converts a single record"
  (let* (
         (name    (bbdb-record-name record))
         (company (bbdb-record-company record))
         (net     (bbdb-record-net record))
         (aka     (bbdb-record-aka record))
         (phone   (bbdb-record-phones record))
         (address (bbdb-record-addresses record))
         (notes   (bbdb-record-notes record))
	 )
    
    (insert
     (format "%s %s\n" bbdb-to-org-contacts-record-prefix name))
    (insert
     (format "%s :PROPERTIES:\n" bbdb-to-org-contacts-record-blanks))

    (when aka
      (insert
       (format "%s :AKA:\t%s\n" bbdb-to-org-contacts-record-blanks
	       (mapconcat (function (lambda(str) str)) aka ", "))))

    (when net
      (insert
       (format "%s :EMAIL:\t%s\n" bbdb-to-org-contacts-record-blanks
	       (mapconcat (function (lambda(str) str)) net " "))))

    (when company
      (insert
       (format "%s :COMPANY:\t%s\n" bbdb-to-org-contacts-record-blanks company)))

    (when phone
      (insert
       (mapconcat
	(function (lambda(rec) 
		    (if (stringp (elt rec 1))
			(format "%s :PHONE_%s:\t%s"
				bbdb-to-org-contacts-record-blanks
				(upcase (elt rec 0))
				(elt rec 1))
		      (let ((len (length rec))
			    (count 2)
			    (output (format "%d" (elt rec 1))))
			(while (< count (1- len))
			  (setq output
				(concat output
					(format "-%d"
						(elt rec count))))
			  (setq count (1+ count)))
			(format "%s :PHONE_%s:\t%s"
				bbdb-to-org-contacts-record-blanks
				(upcase (elt rec 0)) output)))))
	phone "\n"))
      (insert "\n"))

    (insert
     (format "%s :END:\n" bbdb-to-org-contacts-record-blanks))

    (when notes
      (insert
       (format "%s - %s\n" bbdb-to-org-contacts-record-blanks notes)))

    ))


(provide 'bbdb-to-org-contacts)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: org-contacts from bbdb: a starting solution
  2011-03-09 15:18   ` Wes Hardaker
@ 2011-03-10 13:07     ` Eric S Fraga
  0 siblings, 0 replies; 4+ messages in thread
From: Eric S Fraga @ 2011-03-10 13:07 UTC (permalink / raw)
  To: Wes Hardaker; +Cc: emacs-orgmode

Wes Hardaker <wjhns209@hardakers.net> writes:

>>>>>> On Wed, 09 Mar 2011 11:46:50 +0000, Eric S Fraga <e.fraga@ucl.ac.uk> said:
>
> ESF> Are you intending to extend your code for not-so-appropriate fields?  If
> ESF> so, I definitely would like to see the addresses converted and it would
> ESF> be quite useful to have the notes converted entry text for the org entry
> ESF> (i.e. not a property).
>
> I thought about trying to create a generic 'list' of matching 'this' to
> 'that' but hadn't gotten to it yet.

No worries.  Could you, in the meantime, dump out the remaining
information (from the bbdb record) as you do with the notes now (see
below) so that at least the information is not "lost" in the
translation?  That alone would be an excellent addition.

> I'd be happy to change the notes so it went under the properties, if
> that's what you want?  I think you want what is attached.

Yes, that's exactly what I wanted!  Brilliant.

Thanks,
eric

-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.5 (release_7.5.17.gf8ca5.dirty)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-03-10 13:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-08 20:51 org-contacts from bbdb: a starting solution Wes Hardaker
2011-03-09 11:46 ` Eric S Fraga
2011-03-09 15:18   ` Wes Hardaker
2011-03-10 13:07     ` Eric S Fraga

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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).