#!/usr/bin/python # -*- coding: UTF-8 -*- # $Id$ import os import sys import cgi import datetime import xmpp import PyRSS2Gen from jolem_api import JolemAPI # possible config files to look in config_files = ( 'jolem-test.xml', 'jolem.xml', os.environ.get('HOME')+'/jolem.xml', '/etc/jolem.xml', ) class ConfigurationError: pass class ConnectionError: pass class AuthorizationError: pass class NotImplemented: pass """ Outputs an RSS feed for Jolem """ __version__ = "$Revision$" class JolemRSS: """ Builds RSS feed for specified Jabber ID """ def __init__(self, jid, config_file): self.jid = xmpp.protocol.JID(jid) self.api = JolemAPI(config_file) def generate(self, entries=30): """ Generates the RSS feed for the most recent status updates """ status_sets = self.api.getRecentStatus(self.jid, entries) rss_items = [] for status_set in status_sets: rss_items.append(PyRSS2Gen.RSSItem( title = status_set[2], description = status_set[3], guid = PyRSS2Gen.Guid("%s %s" % (self.jid.getStripped(), \ status_set[0])), pubDate = status_set[0], author = self.jid.getStripped())) rss = PyRSS2Gen.RSS2( title = self.jid.getStripped() + " Status", link = "http://svn.silfreed.net/jolem", description = "XMPP status and message changes", lastBuildDate = datetime.datetime.now(), items = rss_items, ) return rss def main(): """ Main execution starting point for this file """ # get jabber id to lookup url_params = cgi.parse() jid = None if 'jid' in url_params: jid = url_params['jid'][0] # find config file from list of possible config files config_file = None for test_config_file in config_files: if os.path.isfile(test_config_file): config_file = test_config_file break if config_file is None: print "Config file was not found" return if jid is not None: jrss = JolemRSS(jid, config_file) rss_feed = jrss.generate() # rss_feed.write_xml(open("jolem_rss.xml", "w")) rss_feed.write_xml(sys.stdout) if __name__ == '__main__': main()