plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
This commit is contained in:
parent
0698b69344
commit
5aa76d7d23
1 changed files with 54 additions and 1 deletions
|
|
@ -21,10 +21,11 @@ from sat.core.i18n import _
|
|||
from logging import debug, info, warning, error
|
||||
from twisted.internet import defer
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.words.xish.domish import Element
|
||||
from sat.core import exceptions
|
||||
from wokkel import disco, data_form, iwokkel
|
||||
from zope.interface import implements
|
||||
|
||||
from feed import date
|
||||
import uuid
|
||||
import urllib
|
||||
|
||||
|
|
@ -105,6 +106,11 @@ class GroupBlog(object):
|
|||
method=self.getLastGroupBlogs,
|
||||
async=True)
|
||||
|
||||
host.bridge.addMethod("getLastGroupBlogsAtom", ".plugin",
|
||||
in_sign='sis', out_sign='s',
|
||||
method=self.getLastGroupBlogsAtom,
|
||||
async=True)
|
||||
|
||||
host.bridge.addMethod("getMassiveLastGroupBlogs", ".plugin",
|
||||
in_sign='sasis', out_sign='a{saa{ss}}',
|
||||
method=self._getMassiveLastGroupBlogs,
|
||||
|
|
@ -496,6 +502,53 @@ class GroupBlog(object):
|
|||
#TODO: we need to use the server corresponding the the host of the jid
|
||||
return self._initialise(profile_key).addCallback(initialised)
|
||||
|
||||
def getLastGroupBlogsAtom(self, pub_jid_s, max_items=10, profile_key='@NONE@'):
|
||||
"""Get the atom feed of the last published microblogs
|
||||
@param pub_jid: jid of the publisher
|
||||
@param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7)
|
||||
@param profile_key: profile key
|
||||
@return: atom XML feed (unicode)
|
||||
"""
|
||||
pub_jid = jid.JID(pub_jid_s)
|
||||
|
||||
def removeAllURIs(element):
|
||||
"""Recursively remove the URIs of the element and its children.
|
||||
Without that, the entry would still be valid but not displayed
|
||||
by Firefox nor Thunderbird (and probably more readers)"""
|
||||
element.uri = element.defaultUri = None
|
||||
for child in element.children:
|
||||
if isinstance(child, Element):
|
||||
removeAllURIs(child)
|
||||
|
||||
def items2feed(items, pub_jid, client):
|
||||
feed = """<?xml version="1.0" encoding="utf-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>%(user)s's blogposts</title>
|
||||
<link href="%(feed)s" rel="self" />
|
||||
<link href="%(blog)s" />
|
||||
<id>%(id)s</id>
|
||||
<updated>%(date)s</updated>\n""" % {'user': pub_jid.user,
|
||||
'feed': 'http://%s/blog/%s/atom.xml' % (client.jid.host, pub_jid.user),
|
||||
'blog': 'http://%s/blog/%s' % (client.jid.host, pub_jid.user),
|
||||
'id': self.getNodeName(pub_jid),
|
||||
'date': date.rfc3339.timestamp_from_tf(date.rfc3339.tf_utc())}
|
||||
for item in items:
|
||||
entry = item.firstChildElement()
|
||||
removeAllURIs(entry)
|
||||
feed += " " + entry.toXml().encode('utf-8') + "\n"
|
||||
return feed + "</feed>"
|
||||
|
||||
def initialised(result):
|
||||
profile, client = result
|
||||
d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(pub_jid),
|
||||
max_items=max_items, profile_key=profile_key)
|
||||
d.addCallback(items2feed, pub_jid, client)
|
||||
d.addErrback(lambda ignore: {}) # TODO: more complete error management (log !)
|
||||
return d
|
||||
|
||||
#TODO: we need to use the server corresponding the the host of the jid
|
||||
return self._initialise(profile_key).addCallback(initialised)
|
||||
|
||||
def getGroupBlogComments(self, service_s, node, profile_key='@NONE@'):
|
||||
"""Get all comments of given node
|
||||
@param service_s: service hosting the node
|
||||
|
|
|
|||
Loading…
Reference in a new issue