5065 comments
2219 subscribers
4799 on Twitter
Subscribe! Feed reader E-mail

Emacs + LinkedIn: Another totally idiosyncratic bit of code

The following code should not be run until you’ve backed up your Big
Brother Database and sacrificed a chicken. It goes through the list of
people in your exported LinkedIn CSV, creates BBDB records if
necessary, adds a linkedin mail alias, and notices new e-mail
addresses and job titles. Call sacha/linkedin-import from the CSV.
Needs csv.el
and
lookout.el,
which you should load before running this code.

If anyone else ever finds this useful, I’ll be quite surprised.

(require 'csv)
(require 'lookout)

(setq lookout-bbdb-mapping-table
      '(("lastname" "Last Name")
        ("firstname" "First Name")
        ("company" "Company")
        ("job" "Job Title")
        ("net" "E-mail Address")))

(defun sacha/lookout-bbdb-check-linkedin (line)
  (let* ((lastname  (lookout-bbdb-get-value "lastname" line))
	 (firstname (lookout-bbdb-get-value "firstname" line))
	 (company   (lookout-bbdb-get-value "company" line))
         (job       (lookout-bbdb-get-value "job" line))
	 (net       (lookout-bbdb-get-value "net" line))
	 (addr1     (lookout-bbdb-get-value "addr1" line))
	 (addr2     (lookout-bbdb-get-value "addr2" line))
	 (addr3     (lookout-bbdb-get-value "addr3" line))
	 (phones    (lookout-bbdb-get-value "phones" line t)) ;; !
	 (notes     (lookout-bbdb-get-value "notes" line ))
         (j (concat job ", " company))
	 (otherfields (lookout-bbdb-get-value "otherfields" line t))
	 (addrs nil)
         (n (concat "^" firstname " " lastname))
	 (record (or (bbdb-search (bbdb-records) n)
                     (bbdb-search (bbdb-records) nil nil net)))
	 (message ""))
    (unless record
      (if (string= company "") (setq company nil))
      (if (string= notes "") (setq notes nil))
      (if (and addr1 (> (length addr1) 0))
	  (add-to-list 'addrs (vector "Address 1" (list addr1) "" "" "" "")))
      (if (and addr2 (> (length addr2) 0))
	  (add-to-list 'addrs (vector "Address 2" (list addr2) "" "" "" "")))
      (if (and addr3 (> (length addr3) 0))
	  (add-to-list 'addrs (vector "Address 3" (list addr3) "" "" "" "")))
      (setq record (list
                    (lookout-bbdb-create-entry (concat firstname " " lastname)
                                               (concat job ", " company)
                                               net
                                               addrs
                                               phones
                                               notes
                                               otherfields))))
    ;; Check if net has changed
    (when record
      (setq record (car record))
      (let ((nets (bbdb-record-net record)))
        (unless (member net nets)
          ;; New e-mail address noticed, add to front of list
          (add-to-list 'nets net)
          (bbdb-record-set-net record nets)
          (message "%s %s: New e-mail address noticed: %s" firstname lastname net)))
      ;; Check if job title and company have changed
      (when (or job company)
        (cond
         ((string= (or (bbdb-record-company record) "") "")
          (bbdb-record-set-company record j))
         ((string= (bbdb-record-company record) j)
          nil)
         (t
          (bbdb-record-set-notes
           record
           (concat "Noticed change from job title of "
                   (bbdb-record-company record)
           "\n"
           (bbdb-record-notes record)))
          (message "%s %s: Noticed change from job title of %s to %s"
                   firstname lastname (bbdb-record-company record) j)
          (bbdb-record-set-company record j))))
      (let* ((propsym bbdb-define-all-aliases-field)
             (oldaliases (bbdb-record-getprop record propsym)))
        (if oldaliases (setq oldaliases
                             (if (stringp oldaliases)
                                 (bbdb-split oldaliases ",")
                               oldaliases)))
        (add-to-list 'oldaliases "linkedin")
        (setq oldaliases (bbdb-join oldaliases ", "))
        (bbdb-record-putprop record propsym oldaliases)))))

(defun lookout-bbdb-create-entry (name company net addrs phones notes
				       &optional otherfields)
  (when (or t (y-or-n-p (format "Add %s to bbdb? " name)))
    ;;(message "Adding record to bbdb: %s" name)
    (let ((record (bbdb-create-internal name company net addrs phones notes)))
      (unless record (error "Error creating bbdb record"))
      (mapcar (lambda (i)
		(let ((field (make-symbol (aref i 0)))
		      (value (aref i 1)))
		  (when (and value (not (string= "" value)))
		    (bbdb-insert-new-field record field value))))
	      otherfields)
      record)))

(defun lookout-bbdb-get-value (key entry &optional as-vector-list)
  "Returns the value for a key from a lispified csv line, using the mapping
table."
  (let* ((table (if (listp lookout-bbdb-mapping-table)
		    lookout-bbdb-mapping-table
		  (symbol-value lookout-bbdb-mapping-table)))
	 (mapped-keys (cdr (assoc key table)))
	 (result nil)
	 (separator ""))

    (unless as-vector-list
      (setq result ""))
    (when mapped-keys
      (if (stringp mapped-keys)
          (setq mapped-keys (list mapped-keys)))
      (mapcar (lambda (i)
                ;;(message "%s...%s" i (cdr (assoc i entry)))
                (let ((value (cdr (assoc i entry))))
                  (unless (string= "" value)
                    (if as-vector-list
                        (add-to-list 'result (vector i value))
                      (setq result (concat result separator value)))
                    (setq separator " "))))
              mapped-keys))
    ;;(message "%s" result)
    result))

(defun sacha/linkedin-import ()
  (interactive)
  (mapcar
   'sacha/lookout-bbdb-check-linkedin
   (csv-parse-buffer)))

On Technorati: , , ,

Short URL: http://sachachua.com/blog/p/3884

3 Responses to “Emacs + LinkedIn: Another totally idiosyncratic bit of code”

  1. Hi Sacha!

    well, testing this potentially useful code: I get

    Making completion list…
    mapcar: Wrong number of arguments: (lambda (first-line-contains-keys &optional buffer coding-system) “Parse a buffer containing CSV data, return data as a list of alists.

    Regards

    Gijs

  2. Gijs…

    did you actually sacrifice a chicken like the instruction says? Pics man – or it didn’t happen.
    I’m sticking w/ vim thanks.

    Mon

  3. Gijs: Might be a problem with csv.el? Maybe doublecheck that that works…

Comment, share a thought, ask a question...

Please comment as you, not your organization.





 

On This Day...

  • 2011: Getting better at working at the office — I’ll be working on a new project with a local coworker soon, which means I’ll probably come to the office [...]
  • 2010: Book: Getting to Yes — (c) 2010 David Prior – Creative Commons Attribution 2.0 Licence Getting to Yes: Negotiating Agreement Without Giving In Roger [...]
  • 2009: Weekly review: Sept 20 and Sept 27, 2009 — zomg, just realized I’d skipped the weekly review for last week. Hmm. Clearly, I need to sort out my task [...]
  • 2008: Learning sewing and French — Sewing is turning out to be surprisingly fun. I finished the wool jumper-dress (Simplicity 4097), learning how to work with [...]
  • 2007: The Kitten-ful Life — One of my friends has the absolutely best setup for kittendom. She fosters kittens for the Toronto Human Society, taking in [...]
  • 2007: When there’s more than one way to do things — Writing about Emacs turns out to be difficult. There are so many ways to do something. My goal for this book [...]
  • 2007: Work permit on its way — A CIC official called me two days ago to clarify something on my application for a post-graduate work permit. When we [...]
  • 2007: My SecondLife interviewbot is coming along nicely — I’d have given up on the Linden Scripting Language long ago if Stephen Perelgut hadn’t wanted this bot so much. It’s [...]
  • 2006: Conference Commando: Networking with Nametags — Whenever I go to a networking event and see people without nametags or with nametags that only have their first names, [...]
  • 2006: Emacs: Animation in presentations — … and because this is just so endearingly old-school and crazily Emacs, here’s what’s going to be my title “slide” for [...]
  • 2006: Emacs: BBDB rapid serial visualization — And because it’s good to quickly flash through records once in a while to refresh my memory… (defvar sacha/bbdb-rapid-serial-visualization-delay 1 "*Number of [...]
  • 2006: Emacs: Show only people whom I haven’t pinged since… — One of the things I want in a contact management system is a quick way to find out who I haven’t [...]
  • 2005: On the Philippine Question — An excerpt from the speech of Senator George F. Hoar, in the Beveridge-Hoar Debate on the Philippine Question, delivered in the United [...]
  • 2005: Voice messaging network — Also via Social Software: Yackpack is a pretty social voice messaging thing. Web-based, so it doesn’t hurt to try it [...]
  • 2005: More collaborative software — Via Social Software: Gobby is a cross-platform collaborative editor. Finally!
  • 2005: Jotspot Live — Via TechCrunch: Jotspot Live now open. It’s a hosted wiki for simultaneous collaboration, with slick AJAX and great editing. Interesting…
  • 2005: Collaboration — Also via tech.memeorandum: Chris Pratley: Working as a team with a shared notebook Interesting support for collaboration…
  • 2005: Cognitive analysis of tagging — Rashmi Sinha: A cognitive analysis of tagging Yay! Another paper to add to my research question. Makes sense. Figuring out exactly where [...]
  • 2005: Learning changes — Via Weblogg-ed: Connecting for Life comes this blog post on Elearnspace: Connectivism, which points out that learning these days isn’t [...]
  • 2005: Forrester Consumer Forum report — The numbers are in. 10% of consumers read blogs at least once a week, 6% use RSS, and 4% use [...]
  • 2005: Solopreneurship and the Tipping Point — Small Business Branding: Content Management suggests a curriculum for the solopreneur. The stuff I’m interested in makes up for of [...]
  • 2005: Finding names: the 100th monkey — Charo inducted me into the 100th Monkey club. it’s something we talked about on mensaphilopen about how certain people, given the [...]
  • 2004: THE LAST PROMISE — “I’ll love you forever.” He pressed her fingers to his tear-stained cheeks. She pulled her hands away. “No more promises. That way, [...]
  • 2004: How to be a programmer — http://samizdat.mines.edu/howto/HowToBeAProgrammer.html Picked it up off my http://del.icio.us/inbox/sachac/ . Wonderful stuff. =)