Using Jaiku API with Python
I’ve slowly fallen in love with Jaiku. It’s a microblogging platform much like Twitter, but with fun features like ability to add feeds from other services (like Flickr, Ma.gnolia.com, Last.fm or any arbitrary source) to your stream and a nifty client for Series 60 phones. Jaiku also has an open API for easy hacking. I was amazed how easy it was to use.
My goal was to get my current presence data and location from Jaiku. After 30 minutes of coding (of which I watched the Simpsons about 20 minutes) I had the following 25 lines of code in my jaiku.py:
from django.utils import simplejson
from urllib import urlopen
from time import strptime
from datetime import datetime, timedelta
JAIKU_USERNAME = 'uninen'
def get_jaiku_presence():
"""Returns user Jaiku presence as dict or False if errors."""
url = 'http://%s.jaiku.com/presence/last/json' % JAIKU_USERNAME
try:
result = simplejson.load(urlopen(url))
# pythonize needed fields
time = strptime(result['created_at'], "%Y-%m-%dT%H:%M:%S GMT")
result['created_at'] = datetime(*time[:5]) + timedelta(hours=3)
result['comments'] = len(result['comments']) or False
return result
except IOError:
return False
It’s very simple and dead easy to use:
In [1]: from unessanet.misc.jaiku import get_jaiku_presence
In [2]: get_jaiku_presence()
Out[2]:
{u'comments': False,
u'content': u'Savitehtaankatu, Turku, Finland',
u'created_at': datetime.datetime(2007, 8, 17, 0, 20),
u'created_at_relative': u'3 hours, 8 minutes ago',
u'icon': u'',
u'id': u'9552365',
u'location': u'Savitehtaankatu, Turku, Finland',
u'title': u'Enjoying the rain',
u'url': u'http://Uninen.jaiku.com/presence/9552365',
u'user': {u'avatar': u'http://jaiku.com/image/13/avatar_32113_t.jpg',
u'first_name': u'Ville',
u'last_name': u'S\xe4\xe4vuori',
u'nick': u'Uninen',
u'url': u'http://Uninen.jaiku.com'}}
Feel free to modify this to your needs.
Next up is a system for storing these presences to a local database and drawing a location trail to Google Maps or something similar…
PS. My Jaiku stream is at uninen.jaiku.com :)












