Telegram bot & feed 解析器-> 在 1 条消息而不是 2 条消息中回复 rss feed

Telegram bot & feed parser-> reply rss feed in 1 msg instead of 2

我正在尝试让我的 Telegram 机器人通过 RSS 提要回复新闻。为此,我使用了模块 Feedparser。现在我已经设法让它工作了,但是机器人为每个提要项目发送了 2 条单独的消息。第一个包含提要摘要,第二个包含 link。我想更改代码,以便它在 1 条消息中发送。我尝试了两种不同的方法,但都出现了错误。

每件 2 条消息的工作方法:

elif text == "/news":
            for i in range(3):
                reply (feed.entries[i].summary)
                reply (feed.entries[i].link)

我失败的修复:

修正1

elif text == "/news":
            for i in range(3):
                reply ((feed.entries[i].summary)
                       (feed.entries[i].link))

错误1

Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/e~thalia-bot/1.391503855076259816/main.py", line 169, in post
(feed.entries[i].link))
TypeError: 'unicode' object is not callable

修正2

elif text == "/news":
            for i in range(3):
                reply (feed.entries[i].summary.link)

错误2

Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/e~thalia-bot/1.391503917377816930/main.py", line 168, in post
reply (feed.entries[i].summary.link)
AttributeError: 'unicode' object has no attribute 'link'

我不确定我在这里做错了什么,查找错误以尝试修复但尚未找到有效的解决方案。如果有人能指出正确的方向,我将不胜感激。

你可以试试

elif text == "/news":
  for i in range(3):
    reply("{} {}".format(feed.entries[i].summary, feed.entries[i].link))

如果您希望下一行有link,您可以将“{} {}”中的空格替换为“\n”(换行符)。