emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Basic vcard-to-org-contacts converter
@ 2014-03-24 19:25 Titus von der Malsburg
  2014-03-25  0:07 ` Feng Shu
  0 siblings, 1 reply; 3+ messages in thread
From: Titus von der Malsburg @ 2014-03-24 19:25 UTC (permalink / raw)
  To: emacs-orgmode


Hi list!

I decided to give org-contacts a try.  Since there doesn't seem to be a
facility for importing contacts in vcard format, I wrote a little Python
script for that.  Perhaps someone on this list finds it useful.

  https://gist.github.com/tmalsburg/9747104

The script uses the Python package vobject for parsing vcard files.  On
Debian-like systems this package is available as python-vobject.  I
tested the script with contacts exported from Apple's iCloud service and
that worked well.  However, the vcard format is somewhat messy and I
don't know what happens with vcard files generated in other contact
managers.  Use at your own risk.

If there's interest, I might migrate the script to a proper Github
repository and develop it further, i.e., merge your pull-requests ;-)

  Titus

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

* Re: Basic vcard-to-org-contacts converter
  2014-03-24 19:25 Basic vcard-to-org-contacts converter Titus von der Malsburg
@ 2014-03-25  0:07 ` Feng Shu
  2014-03-25  0:52   ` Ken Mankoff
  0 siblings, 1 reply; 3+ messages in thread
From: Feng Shu @ 2014-03-25  0:07 UTC (permalink / raw)
  To: emacs-orgmode

Titus von der Malsburg <malsburg@posteo.de> writes:

> Hi list!
>
> I decided to give org-contacts a try.  Since there doesn't seem to be a
> facility for importing contacts in vcard format, I wrote a little Python
> script for that.  Perhaps someone on this list finds it useful.
>
>   https://gist.github.com/tmalsburg/9747104
>
> The script uses the Python package vobject for parsing vcard files.  On
> Debian-like systems this package is available as python-vobject.  I
> tested the script with contacts exported from Apple's iCloud service and
> that worked well.  However, the vcard format is somewhat messy and I
> don't know what happens with vcard files generated in other contact
> managers.  Use at your own risk.

Import from csv is a solution too, I use the below hack functions to import a
csv file...

#+begin_src

(defun eh-org-contacts-parse-csv-line (line)
  "Build a org contact from a csv line"
  (let ((list (split-string line ",")))
    (concat "* " (nth 0 list) "\n"
            ":PROPERTIES:\n"
            ":PHONE: " (nth 1 list) "\n"
            ":EMAIL: " (let ((string (nth 2 list)))
                         (if (string-match-p "@" string) string
                           (if (> (length string) 0) (concat string "@qq.com")))) "\n"
            ":NOTE: "  (mapconcat 'identity (nthcdr 3 list) "; ") "\n"
            ":END:\n")))

(defun eh-org-contacts-csv-import (&optional filename)
  "Convert a csv file to org contacts format and insert current point"
  (interactive)
  (let ((file (if filename filename (read-file-name "CSV file:")))
        (buffer (current-buffer))
        (point (point))
        contacts-string)
  (with-temp-buffer
    (insert-file-contents file)
    (goto-char (point-min))
    (while (< (point) (point-max))
      (setq contacts-string (concat contacts-string (eh-org-contacts-parse-csv-line (buffer-substring (point) (progn (end-of-line) (point)))) "\n"))
      (forward-line 1)
      (beginning-of-line 1)))
  (switch-to-buffer buffer)
  (goto-char point)
  (insert contacts-string)))

#+end_src

>
> If there's interest, I might migrate the script to a proper Github
> repository and develop it further, i.e., merge your pull-requests ;-)
>
>   Titus

-- 

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

* Re: Basic vcard-to-org-contacts converter
  2014-03-25  0:07 ` Feng Shu
@ 2014-03-25  0:52   ` Ken Mankoff
  0 siblings, 0 replies; 3+ messages in thread
From: Ken Mankoff @ 2014-03-25  0:52 UTC (permalink / raw)
  To: Feng Shu; +Cc: emacs-orgmode


And I posted a solution a few weeks ago that parses the Apple
AddressBook to Org contacts. Wrapped in a LaunchAgent that runs the
script whenever the addressbook is updated (file timestamp changes)
and it keeps mu4e up-to-date with Apple OS X and iDevices.

  -k.

On 2014-03-24 at 20:07, Feng Shu wrote:
> Titus von der Malsburg <malsburg@posteo.de> writes:
>
>> Hi list!
>>
>> I decided to give org-contacts a try.  Since there doesn't seem to be a
>> facility for importing contacts in vcard format, I wrote a little Python
>> script for that.  Perhaps someone on this list finds it useful.
>>
>>   https://gist.github.com/tmalsburg/9747104
>>
>> The script uses the Python package vobject for parsing vcard files.  On
>> Debian-like systems this package is available as python-vobject.  I
>> tested the script with contacts exported from Apple's iCloud service and
>> that worked well.  However, the vcard format is somewhat messy and I
>> don't know what happens with vcard files generated in other contact
>> managers.  Use at your own risk.
>
> Import from csv is a solution too, I use the below hack functions to import a
> csv file...
>
> #+begin_src
>
> (defun eh-org-contacts-parse-csv-line (line)
>   "Build a org contact from a csv line"
>   (let ((list (split-string line ",")))
>     (concat "* " (nth 0 list) "\n"
>             ":PROPERTIES:\n"
>             ":PHONE: " (nth 1 list) "\n"
>             ":EMAIL: " (let ((string (nth 2 list)))
>                          (if (string-match-p "@" string) string
>                            (if (> (length string) 0) (concat string "@qq.com")))) "\n"
>             ":NOTE: "  (mapconcat 'identity (nthcdr 3 list) "; ") "\n"
>             ":END:\n")))
>
> (defun eh-org-contacts-csv-import (&optional filename)
>   "Convert a csv file to org contacts format and insert current point"
>   (interactive)
>   (let ((file (if filename filename (read-file-name "CSV file:")))
>         (buffer (current-buffer))
>         (point (point))
>         contacts-string)
>   (with-temp-buffer
>     (insert-file-contents file)
>     (goto-char (point-min))
>     (while (< (point) (point-max))
>       (setq contacts-string (concat contacts-string (eh-org-contacts-parse-csv-line (buffer-substring (point) (progn (end-of-line) (point)))) "\n"))
>       (forward-line 1)
>       (beginning-of-line 1)))
>   (switch-to-buffer buffer)
>   (goto-char point)
>   (insert contacts-string)))
>
> #+end_src
>
>>
>> If there's interest, I might migrate the script to a proper Github
>> repository and develop it further, i.e., merge your pull-requests ;-)
>>
>>   Titus

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

end of thread, other threads:[~2014-03-25  0:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-24 19:25 Basic vcard-to-org-contacts converter Titus von der Malsburg
2014-03-25  0:07 ` Feng Shu
2014-03-25  0:52   ` Ken Mankoff

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