Twitter, Email, and SMS integration, all for the price of one

We've been crazy busy these last couple of weeks, with a lot of client work, and I only now find the time to write down these thoughts that have been on my mind for quite a while.

A couple of years ago I built a time management system of my own because I couldn't find anything out there with the functionality that I needed. On the surface this system (which I lovingly named Heraclitus, in honor of the greek philosopher who made it impossible for us to bathe in the same river twice) is just a regular calendar & to-do list combo. What really makes Heraclitus so special for me, though, is the fact that instead of just checking things off the list and removing them from the database, Heraclitus keeps logs of everything I've done, along with notes associated with each task. This means that I can go back later and find, for example, the exact list of commands that I happened to use on April 15th, 2007 to create a new AMI for EC2 (and it's all searchable, of course).I use Heraclitus constantly, not just as a way to organize my day, but also as a knowledge base of everything that I've done, every article I've read, every client conversation I've had, every technical problem I've encountered and the solutions I've found, etc. etc. etc.

Heraclitus lives and runs on my laptop, which goes with me almost everywhere. There are, however, times when I am away from the machine, and of course I'd still like to be able to schedule a task within the system, or record an idea, or check something off. Sometimes I'd like to do that from my cell phone, other times via the more convenient email, and other times even via Twitter (for example to log a little remark about a interesting tweet that I've just read without having to leave Twitterrific). That functionality would be great to have but, needless to say, I've never had the time nor the desire to write all the three necessary interfaces to support it.

But the other day I realized what should have been obvious all along. Because Twitter can talk to cell phones and to email (via TwitterMail), all I had to do was build an interface to Twitter and, for free, I'd get the two other interfaces. And so I prompty added a background runner to my Heraclitus system, a simple script that periodically monitors direct messages to a Twitter account that I created for this purpose. Thanks to rest_client and hpricot, the code is really simple:

   require 'rubygems'
   require 'rest_client'
   require 'hpricot' 
    
   last_direct_id = TwitterCheck.find_by_name('last_direct_id').value
   while true do
       # Wrap in a begin/rescue, because Twitter *will* fail
       begin
           url = 'http://account:pwd@twitter.com/direct_messages.xml?since_id=#{last_direct_id}'
           dms = Hpricot( RestClient.get(url)
           (dms/'direct_message').each do |m|
               sender_name = (m/'sender/screen_name').inner_html 
               next unless sender_name == '[myaccount]' 

               # Get the text
               id = (m/'/id').inner_html
               text = (m/'text').inner_html 

               # If this fails, don't record the change
               begin
			        date, descr = text.split(/ /, 3)
			        Task.create(:name => descr, :on_day => date)
			        TwitterCheck.update_all("value = #{id}", "name = 'last_direct_id'")
					last_direct_id = id
               rescue
                   ActionController::Base.logger.warn('An error occurred: #{$!}')
               end
           end
       rescue
           ActionController::Base.logger.warn('An error occurred: #{$!}')
       end 
       sleep 240
   end 

The script uses a database table to record that last message that it received, and every two minutes it requests from Twitter the new direct messages for that Heraclitus account. If there are any, it verifies that the message was sent by me (so that other people cannot spam me), and then it parses the message according to my rules and adds it to my schedule. So now I can go to Twitter and send a message to my account like this:

   d myheraclitus 04-15 Pay Taxes @ 2:30

and in a couple of minutes it's listed on my to-do. The cool thing is that I can also text the same message from my cell phone (using shortcuts so I don't have to type all that text), and I can email it to a TwitterMail account that then forwards it to Twitter, and from there to my Heraclitus.

 

All three interfaces for the price of one!

Comments (0)

Leave a comment...