emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] org-contacts from bbdb: a starting solution


From: Wes Hardaker
Subject: Re: [O] org-contacts from bbdb: a starting solution
Date: Wed, 09 Mar 2011 07:18:20 -0800
User-agent: Gnus/5.110012 (No Gnus v0.12) Emacs/23.2 (gnu/linux)

>>>>> On Wed, 09 Mar 2011 11:46:50 +0000, Eric S Fraga <address@hidden> 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/
(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)

reply via email to

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