async def publish(self, server, node, entry): iq = self.Iq(stype="set", sto=server) iq['pubsub']['publish']['node'] = node item = pubsub.Item() # character / is causing a bug in movim. replacing : and , with - in id. It provides nicer urls. rex = re.compile(r'[:,\/]') item['id'] = rex.sub('-', str(entry.id)) ent = ET.Element("entry") ent.set('xmlns', NS_ATOM) title = ET.SubElement(ent, "title") title.text = entry.title updated = ET.SubElement(ent, "updated") updated.text = entry.updated if hasattr(entry.content[0], 'type'): content = ET.SubElement(ent, "content") content.set('type', entry.content[0].type) content.text = entry.content[0].value if hasattr(entry, 'links'): for l in entry.links: link = ET.SubElement(ent, "link") link.set('href', l['href']) link.set('type', l['type']) link.set('rel', l['rel']) if hasattr(entry, 'tags'): for t in entry.tags: tag = ET.SubElement(ent, "category") tag.set('term', t.term) if hasattr(entry, 'authors'): author = ET.SubElement(ent, "author") name = ET.SubElement(author, "name") name.text = entry.authors[0].name if hasattr(entry.authors[0], 'href'): uri = ET.SubElement(author, "uri") uri.text = entry.authors[0].href item['payload'] = ent iq['pubsub']['publish'].append(item) task = iq.send(timeout=5) try: await task except (IqError, IqTimeout) as e: print(e) pass
async def publish(self, server, node, entry): iq = self.Iq(stype="set", sto=server) iq['pubsub']['publish']['node'] = node item = pubsub.Item() item['id'] = entry.id ent = ET.Element("entry") ent.set('xmlns', NS_ATOM) title = ET.SubElement(ent, "title") title.text = entry.title updated = ET.SubElement(ent, "updated") updated.text = entry.updated if hasattr(entry.content[0], 'type'): content = ET.SubElement(ent, "content") content.set('type', entry.content[0].type) content.text = entry.content[0].value if hasattr(entry, 'links'): for l in entry.links: link = ET.SubElement(ent, "link") link.set('href', l['href']) link.set('type', l['type']) link.set('rel', l['rel']) if hasattr(entry, 'authors'): author = ET.SubElement(ent, "author") name = ET.SubElement(author, "name") name.text = entry.authors[0].name if hasattr(entry.authors[0], 'href'): uri = ET.SubElement(author, "uri") uri.text = entry.authors[0].href item['payload'] = ent iq['pubsub']['publish'].append(item) task = iq.send(timeout=5) try: await task except IqError: raise