def atom2hash(self, elem): """ Convert an atom domish element to a dictionary for template processing. """ args = {} args['id'] = str(elem.id) id, args['idname'] = str(elem.id).split(":",1) args['categories'] = [] cats = domish.generateElementsNamed(elem.children, 'category') for cat in cats: args['categories'].append(cat['term']) if elem.content: args['content'] = str(elem.content) elif elem.title: args['content'] = str(elem.title) if elem.published: args['published'] = str(elem.published) else: args['published'] = str(datetime.datetime.now()) if elem.updated: args['updated'] = str(elem.updated) else: args['updated'] = str(datetime.datetime.now()) if elem.title: args['title'] = str(elem.title) elif elem.id: args['title'] = str(elem.id) else: args['title'] = 'No Title' return args
def format_payload(self, payload): """ Render the payload into a notification. If available, this uses the anyMeta specific 'figure' links to point to scaled-and-cropped versions of the image used for the actor (icon) or the object (picture). """ verbs = set([unicode(element) for element in payload.elements(NS_ACTIVITY_SPEC, 'verb')]) template = None for verb in self.supportedVerbs: if verb in verbs: template = self.texts[self.feed.language]['activity_verbs'][verb] break if template is None: return None if payload.agent and verb not in self.agentVerbs: return None from twisted.words.xish.domish import generateElementsNamed actorTitle = unicode(generateElementsNamed(payload.author.elements(), 'name').next()) figureURI = None for element in payload.author.elements(NS_ATOM, 'link'): if element.getAttribute('rel', 'alternate') == 'figure': figureURI = element.getAttribute('href') break if figureURI: figureURI += '?width=80&height=80&filter=crop' pictureURI = None for element in payload.object.elements(NS_ACTIVITY_SPEC, 'object-type'): if unicode(element) == TYPE_ATTACHMENT: for element in payload.object.elements(NS_ATOM, 'link'): if element.getAttribute('rel', 'alternate') == 'figure': pictureURI = element.getAttribute('href') break if pictureURI: pictureURI += '?width=480' vars = {} if payload.object and payload.object.title: vars['object'] = unicode(payload.object.title) if payload.target and payload.target.title: vars['target'] = unicode(payload.target.title) subtitle = template % vars notification = { 'title': actorTitle, 'subtitle': subtitle, 'via': self.getVia() } if figureURI: notification['icon'] = figureURI if pictureURI: notification['picture'] = pictureURI return notification