«

»

Aug
01

Twitter + ttytter + perl + Prowl = iPhone Push Goodness

Version 3.0 of the Apple iPhone OS now allows push notifications.  However, for security reasons (presumably), Apple requires that push notifications must flow through their server, and are only allowed to be delivered to native applications. 

Prowl is a new application which allows notifications to be pushed to the iPhone from applications like Growl for Windows or Macs.  Fortunately, the developer has also implemented an API so that one can easily submit push notifications from virtually any programming language which is able to talk to it via the web.

So what?  Well, as I am a big fan of Twitter, I follow enough people that I am often unable to keep up with the flow of tweets.  I had resorted to following the most important posters via RSS, but now I am able to follow their accounts and have any posts they submit pushed to my iPhone as a notification.

Requirements

  1. The Prowl application for the iPhone
  2. The ttytter Twitter client, which runs anywhere Perl does (requires LWP::UserAgent)
  3. A Twitter account – I use a secondary account which follows only those people from whom I want to receive push notifications
  4. The perl script linked below, or one of your creation

Setup

As this uses Prowl, you must purchase that application and download it to your iPhone.  After installation, you can go to the Prowl website, log into your account, and grab a copy of your API key which will allow the script to post notifications to your phone.  As written, the script expects to find that API key in a file called .prowlkey in your home directory.  If you keep it somewhere else, edit the path on Line 27 of the script:

[cce]
if (open(APIKEYFILE, $ENV{‘HOME’} . “/.prowlkey”)) {
[/cce]

Next, you must download and configure the ttytter Twitter client.  Usually, this is just a matter of creating a .ttytterrc file in your home directory.  Note, that if you configure it to use your primary Twitter account, it will forward every tweet you see to your iPhone.  For this reason, I created a secondary Twitter account and followed only a select few people.  Make sure you test this before continuing.

If ttytter is running as expected, Perl is properly installed, so the last prerequisite is to ensure that the Perl module LWP::UserAgent is installed.  From the command line, type or paste the following line.

[cce]perl -e ‘use LWP::UserAgent’[/cce]

If it simply returns a command prompt, your are set.  If you receive an error, then either use your distributions package manager or CPAN to install the libwww-perl module.

The last step is to copy the script to your computer.  You can view and copy the source code here or download it directly from here.  Put the script somewhere accessible to the ttytter application.  I placed both in $HOME/bin and simply named it ttytter-prowl.pl.

Running

Now, to get everything working, simply start ttytter with the -lib=path/to/twitter-prowl.pl (and possibly the -daemon) arguments.  Using -lib will tell ttytter to process that script for each received tweet.  The -daemon argument tells ttytter to fork into the background and run as a daemon.  I tend to run mine in screen so I can check on it, but I intend to move it to daemon mode.

[cc lang="bash"]$ ttytter -lib=ttytter-prowl.pl[/cc]
If everything has gone according to plan, you should soon start receiving tweets on your iPhone as pushes.

Sample Prowl Notification

Sample Prowl Notification