6194 comments
2357 subscribers
Follow me on Twitter (@sachac)
Subscribe! Feed reader E-mail

Emacs: sorting contacts by timestamp

Last September, I started automatically tracking my e-mails. Every
time I sent a message to someone already in my addressbook, his or her
contact record would be updated with the date and subject of the
message. I also made it easy to note that I met someone in person or
that I talked to them on the phone, although this wasn’t automatic.

So now I have almost a year of contact information in my address book.
I was curious—whom haven’t I talked to in a year?

Here are some numbers:

I’ve contacted 396 people in my addressbook since January 1, 2007.

In the past 365 days (2006.09.07 – 2007.09.07), I’ve contacted 670
people in my address book.

93 people have a contact timestamp (maybe the day I met them), but I
haven’t contacted them in the past 365 days. This breaks down to 37
people I haven’t contacted since 2006, 32 people I haven’t contacted
since 2005, and 24 from 2004 or earlier.

1230 records do not have any contact timestamp. Some of these are
bots, some of these are duplicate records I still haven’t gotten
around to merging, others are contacts from before I started tracking
and I haven’t e-mailed or talked to them since.

I figured this out by writing a bit of Emacs Lisp to print a
hyperlinked list of contacts with the date of last contact. This was
then very easy to sort using M-x sort-lines and M-x reverse-region.

For example, here are the people I’ve e-mailed in the last seven days:

2007.09.07 Wayne Young
2007.09.07 Tania Samsonova
2007.09.07 Papa
2007.09.07 Mike Bailey
2007.09.07 Mama
2007.09.07 Leigh Honeywell
2007.09.07 Lawrence J. Rooney
2007.09.07 Kathy Chua
2007.09.07 Don Marti
2007.09.07 Dean Michael Berris
2007.09.07 Ching Valdezco
2007.09.07 Bill Pollock
2007.09.06 Peppy Salita
2007.09.06 Mallory Chua
2007.09.06 John Sullivan
2007.09.06 Clair Ching
2007.09.06 Allan Tan
2007.09.05 Mark Chignell
2007.09.04 Gabriel Mansour
2007.09.03 Thomas Knoll
2007.09.03 Simon Ditner
2007.09.03 Richard Plana
2007.09.03 Neil Ernst
2007.09.03 Mike C. Fletcher
2007.09.03 Michal Jacovi
2007.09.03 Michael J. Muller
2007.09.03 Eugene Jarder
2007.08.31 Simon Rowland
2007.08.31 Jay Goldman

The code below probably won’t work out of the box with you unless
you’re using Planner+BBDB+my mail tracking hacks, but maybe it’ll give
you ideas.

(defun sacha/bbdb-print-with-timestamp (records)
  (while records
    (insert (sacha/bbdb-last-timestamp (car records))
            " |\t"
            (or (sacha/planner-bbdb-annotation-from-bbdb records) "")
            "\n")
    (setq records (cdr records))))

;; (assert (equal (sacha/extract-regexp "a." "ab ac bb") '("ab" "ac")))
(defun sacha/extract-regexp (regexp string &optional group)
  (let (result
        s
        (start 0))
    (while (string-match regexp string start)
      (setq result (cons (match-string (or group 0) string) result))
      (setq start (match-end 0)))
    (nreverse result)))

(defun sacha/bbdb-timestamps (rec)
  "Return a list of timestamps found in the notes or contact field of REC."
  (sort
   (sacha/extract-regexp planner-date-regexp
                         (concat (or (bbdb-record-notes rec) "")
                                 " "
                                 (bbdb-record-getprop rec 'contact)))
   (lambda (a b) (string< b a))))

(defun sacha/bbdb-last-timestamp (rec)
  "Return the most recent timestamp for REC or nil if none."
  (or (car (sacha/bbdb-timestamps rec)) "0000.00.00"))

Yes, I do weird things. Next step for this one: Review the list, see
who I haven't talked to in one year, and decide who I want to get back
in touch with. Also, analyze my e-mail and come up with pretty graphs.

Random Emacs symbol: gnus-server-kill-server - Command: Kill the server on the current line.

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

On This Day...

  • 2012: Having fun with code — I’ve been learning more about Android development so that I can build apps for my smartphone and tablet. I’m starting [...]
  • 2011: Decision: Not getting an Ontario Science Centre family membership — From Sept. 5: We had fun at the Ontario Science Centre. I like science centres. I have lots of great [...]
  • 2010: Redoing things — SCHEDULED: 2010-09-07 Tue 08:00 It took me an extra weekend, but I repainted the chair I’ve been working [...]
  • 2008: Weekly review – Sept 7, 2008 — Last week: Prepared presentation for new media and new generation panel next week. Non-annotated slides up on Slideshare. Got featured on [...]
  • 2008: And just like that, we have a cat — And just like that, we have a cat. Last night, as I was worrying about my paperwork, I heard W- yell, [...]
  • 2007: As me as I could be — Someone asked me last night: If I got a check for $15,000,000, what would I do? I think he expected a [...]
  • 2006: Pamana Fund in honor of Doc Mana — In honor of Doc Mana’s wonderful, wonderful service, the computer science department of the Ateneo de Manila University is setting up The [...]
  • 2006: Doc Mana is retiring in 2007! — From Didith Rodrigo’s blog: Dr. Pablo Manalastas will be retiring in 2007. Nooooo! Who’s going to bounce up and down and talk [...]
  • 2006: Sweet! Career Resource Library totally rocks! — I have in front of me a big yellow binder with news clippings about networking. Awesome. You know what that gives me? [...]
  • 2006: Creating opportunities — Okay, you definitely have to get this book. =) Read the chapter on “Opportunity is Everywhere”, too. And “Repeat, repeat, repeat.” [...]
  • 2006: Raising life by the power of two — When two people share an incredible experience, that experience is not multiplied by two, but rather raised by the power of [...]
  • 2006: Tag team networking — I dropped into the University of Toronto Career Resource Library for a few minutes before my annual health checkup. Seeing [...]
  • 2006: The Secret — On the walk back toward Greg’s Ice Cream for post-sushi dessert, Simon received an invitation from Shane to join him [...]
  • 2006: Quinn’s birthday party – all-you-can-eat sushi! — Quinn celebrated her 22nd birthday party at Mariko Sushi (851 Bloor St W), which has a decent all-you-can-eat menu for CAD [...]
  • 2006: Social networks: Basic, basic feature – multiple e-mail addresses — With the number of e-mail addresses people have, I think that all business networking sites should allow people to have multiple [...]
  • 2005: One of the coolest things about publishing your task list — Comment from Randy Park: Hi Sacha! I just happened to Google my name (for research purposes) and your page came up, with [...]
  • 2003: Conversations with others — Lessons from Jerome: More pragmatic, more concrete examples. It’s really different. Still trying to figure out what the good thing there is.
  • 2003: Nongnu? — http://www.nongnu.org
  • 2003: Pizza patties — recipes — Assembling time 8 minutes Cooking time 30 minutes 1 8-ounce can tomato sauce 3/4 teaspoon dried tarragon, crushed 3/4 teaspoon dried basil, crushed 1/8 teaspon garlic powder 1 beaten egg 1/4 cup fine dry bread [...]
  • 2003: Quick warm-up cocoa — recipes — Assembling time 13 minutes 2 1/2 cups water 2 cups milk 6 envelopes instant cocoa mix 6 tablespoons rum or brandy (optional)   Pressurized dessert topping 6 cinnamon sticks or peppermint sticks (optional) - [...]
  • 2003: Pocket bread appetizers — recipes — Assembling time 5 minutes Cooking time 8 minutes 2 pita bread rounds 3/4 cup shredded caraway cheese or hickory smoke-flavor cheese - Cut pita bread rounds into half [...]
  • 2003: Cheese-frank wrap-ups — recipes — - Assembling time: 15 minutes - Cooking time: 15 minutes 4 pita breat rounds   bottlede barbecue sauce 1/4 cup chopped pitted ripe olives 1 1-pound package (8) frankfurters 4 ounces [...]