Notice:

This page has been converted from a dynamic Wordpress article to a static HTML document. As a result, some content may missing or not rendered correctly.

Posting To Notifo With Python ~ Wed, 09 Jun 2010 01:58:06 +0000

Just after getting to work this morning I discovered an iPhone app and web service named Prowl. It provides a means for sending arbitrary push notifications to your iPhone. This is something I had on my todo list to design and write very soon, so I was very excited to find it. The only downside, and I was totally willing to overlook it, is that the app is not free. The web service is free, but you have to purchase the phone app for it to be any use. However, after doing a little more research I found Notifo.

Notifo is the exact same thing as Prowl, except Notifo is completely free. It looks like Notifo hopes to make money by selling easy push notifications to companies (sort of like the SMS deals you can get some places). Notifo promises to keep the service totally free for users, and users have the ability to send themselves notifications. This is perfect for my purposes.

I had been wanting to write something like Prowl, Notifo, etcetera so that I could send myself notifications when servers I maintain are having difficulties. Typically, these servers maintain an internet connection but the service they provide just stops working. The stop-gap solution was to have the servers email me when they are misbehaving. There are two problems with that:

  1. I had to put my work email on my personal phone.
  2. I couldn't differentiate between important notifications and the junk email that streams into my work inbox.

By removing the notifications from my email, I can get a different notification sound and immediately know I need to fix something. I also get to remove my work email from my phone and save some of my sanity (so much spam).

So I was quite excited to find Notifo and learn that its API is very simple. The only problem was the lack of an implementation in a portable scripting language. Implementations were available forĀ .NET, PHP, and Ruby. Some will read this and say either "What? You didn't go for PHP?!" or "But Ruby is portable!" In response to the first statement, PHP can be used as an command line scripting language, but you usually have to explicitly install it so I don't consider that portable. To the second statement, that might be so, but the Notifo interface is implemented as a "gem" and I don't consider that portable either. Therefore, I decided to write a Python interface.

Python is usually installed, and typically has a robust set of modules installed by default. Indeed, I opted to develop my interface on the most broken OS I have access to -- Red Hat Enterprise Linux 4. It has Python 2.3.4 installed, and it certainly doesn't contain any extras. I was able to write my Python interface using nothing but the installed base modules.

While writing my interface I discovered one other Python script that communicates with Notifo. I could have stopped writing mine, but that script requires extra modules (for parsing the JSON returned by the Notifo service). It also isn't generic. So I kept working and can now present to you PyNotifo.

PyNotifo is nothing more than a simple class that communicates with the Notifo web service. It implements both methods of the service. PyNotifo does not parse the response sent back by the Notifo web service. Instead, it simply returns the full JSON string to whatever script is using the class. I suppose a proper implementation would abstract the JSON into class methods or properties, but I think this way works just fine for a first go. Besides, if I went down that route I would have the same problem as the other Python script -- requiring a JSON module to be installed.

Included with PyNotifo is a simple script that uses the class. This script, named sendNotifoNotification.py, makes it really easy to send Notifo notifications from any other shell script (e.g. a Bash script).

I've put both of these, the class and the script, up on BitBucket with essentially a public domain license. Feel free to use them as you please. Don't hesitate to send me any patches you might develop.

Code,  Python,  Software,  Technology

Comments

Dan said (2010-06-09 12:36:30 GMT):

And then us lazy people just use curl :) Seriously - great find - it's been beeping down here all morning.


James Sumners said (2010-06-09 13:18:15 GMT):

:)

Ah, but you'll have to replicate that curl statement every time you want to add a notification. And you'll likely have to look up the last one you wrote. A little time investment upfront means I get to be twice as lazy later :P