Home > Enlaces y noticias > Simple Identi.ca to Jaiku Bridge

Simple Identi.ca to Jaiku Bridge

November 10th, 2008

Well since I barely use my jaiku account, even when it has xmpp support. Probably is that I’m not really interested on the conversations there and no one uses jaiku channels. It would be a lot better if it used something like “track” the one you find in identispy for identi.ca, twitterspy for twitter and Jance for Pownce.

Anyway I decided that I wouldn’t bother setting yet another account on some random service to update identi.ca,twitter and jaiku at the same time so I decided to write something myself.

After very little effort I came out with this, it’s pretty basic and with ZERO error checking but it does what I want.

I used feedparser and simplejson python modules.

  1. #!/usr/bin/env python
  2.  
  3. import simplejson
  4. import urllib
  5. import feedparser
  6. import time
  7. import re
  8.  
  9. identica_rss="http://identi.ca/IDENTICA_USER/rss"
  10. user = ‘JAIKU_USER’
  11. api_key =‘JAIKU_KEY’
  12.  
  13. class JaikuInterface:
  14.     method = ‘POST’
  15.     api_url = ‘http://api.jaiku.com/json’
  16.     def __init__(self,user,key):
  17.         self.user=user
  18.         self.api_key=key
  19.     def post(self,message):
  20.         body_dict = (
  21.             (‘user’,self.user),
  22.             (‘personal_key’,self.api_key),
  23.             (‘method’,‘presence.send’),
  24.             (‘message’,message)
  25.             )
  26.         body = urllib.urlencode(body_dict)
  27.         try:
  28.             f=urllib.urlopen(self.api_url,body)
  29.             ret = simplejson.loads(f.read())
  30.             f.close()
  31.             if ret[’status’]==u‘ok’:
  32.                 return True
  33.             else:
  34.                 return False
  35.         except:
  36.             return False
  37.  
  38.  
  39.  
  40. jaiku = JaikuInterface(user,key)
  41. last_date = time.mktime(time.gmtime())
  42. oldest = last_date
  43. time_fmt= "%Y-%m-%dT%H:%M:%S+00:00"
  44. striper = re.compile("^deepspawn: ")
  45. stripuser = lambda(x): striper.sub("",x)
  46. while True:
  47.     try:
  48.         identifeed=feedparser.parse(identica_rss)
  49.         for entry in identifeed.entries:
  50.             entry_date = time.strptime(entry.updated,time_fmt)
  51.             entry_date = time.mktime(entry_date)
  52.             if entry_date > last_date:
  53.                 oldest = max(entry_date,oldest)
  54.                 post = stripuser(entry.title)
  55.                 jaiku.post(post)
  56.         last_date=oldest
  57.     except:
  58.         pass
  59.     time.sleep(5*60)
  60.  

Well just replace IDENTICA_USER, JAIKU_USER and JAIKU_KEY with your values and that’s all.

It will poll every 5 minutes the rss and update jaiku with the new dents.

Well that’s all, it’s a small hack I hope someone find this interesting.

, ,

 

Trackbacks

(Trackback URL)

close Reblog this comment
blog comments powered by Disqus