使用 PyRSS2Gen 支持 PubSubHubbub?

发布于 2024-08-23 05:54:31 字数 471 浏览 4 评论 0原文

我正在使用 PyRSS2Gen 生成 RSS 提要,并尝试支持 PubSubHubbub,但我需要添加破坏 RSS 的链接元素。以下是不需要重写为 Atom 的情况下应该可以工作的内容:

<atom:link rel="hub" href="http://example.hub.com" xmlns:atom="http://www.w3.org/2005/Atom">
<atom:link rel="self" href="http://example.com" xmlns:atom="http://www.w3.org/2005/Atom">

我可以以某种方式在 PyRSS2Gen 中添加任意 XML 吗?我认为 element_attrs 或 rss_attrs 不足以完成此任务,或者是吗? PyRSS2Gen.RSS2() 最多需要 1 个链接元素,那么我该怎么做呢?

谢谢你,

金博尔

I'm using PyRSS2Gen to generate a RSS feed and I'm trying to support PubSubHubbub, but I need to add link elements that break RSS. Here's what should work without requiring a rewrite as Atom:

<atom:link rel="hub" href="http://example.hub.com" xmlns:atom="http://www.w3.org/2005/Atom">
<atom:link rel="self" href="http://example.com" xmlns:atom="http://www.w3.org/2005/Atom">

Can I add arbitrary XML in PyRSS2Gen somehow? I don't think element_attrs or rss_attrs are enough to accomplish this, or are they? PyRSS2Gen.RSS2() expects at most 1 link element, so how can I do this?

Thank you,

Kimball

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑脸一如从前 2024-08-30 05:54:31

我查看了 PyRSS2Gen 源代码,看起来您所要做的就是重写 RSS 类的 publish_extensions() 方法。也许是这样的:

import PyRSS2Gen

class MyRSS2(PyRSS2Gen.RSS2):
    def publish_extensions(self, handler):
        PyRSS2Gen._element(handler, 'atom:link', None, {'element': 'attributes here'})

然后使用 MyRSS2 而不是 PyRSS2Gen.RSS2。这是未经测试的代码,我建议在将其投入生产之前检查它,眨眼。

I looked at the PyRSS2Gen source code, and it looks like all you have to do is override the RSS class' publish_extensions() method. Something like this perhaps:

import PyRSS2Gen

class MyRSS2(PyRSS2Gen.RSS2):
    def publish_extensions(self, handler):
        PyRSS2Gen._element(handler, 'atom:link', None, {'element': 'attributes here'})

Then use MyRSS2 instead of PyRSS2Gen.RSS2. That's untested code, I recommend checking it before putting it in production, wink.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文