开发者

How can I get last title from RSS?

开发者 https://www.devze.com 2023-02-17 19:15 出处:网络
I\'m using lua-feeds ( http://code.matthewwild.co.uk/lua-feeds/ ) require \"lua-feeds/feeds\" local feed = feeds.open(\"http://php.net/feed.atom\");

I'm using lua-feeds ( http://code.matthewwild.co.uk/lua-feeds/ )

require "lua-feeds/feeds"

local feed = feeds.open("http://php.net/feed.atom");
for _, entry in ipairs(feed) do
bot.rooms["php@conference.aqq.eu"]:send_me开发者_StackOverflowssage(entry:get_child("title"):get_text().."\n"..entry:get_child("link").attr.href);
end

This is my code, that is getting full RSS. I only want to get the last title and link, how can I do that?


I don't understand how @DeadMG's answer was accepted. It looks terribly wrong to me.

ipairs takes a sequence and returns an iterator over it, so ipairs(feed) is an iterator over the feed. ipairs is called once in the example provided by the OP. The resulting iterator is called several times.

@DeadMG's idea was probably to call the iterator only once. This is how it would look:

local f, v, i = ipairs(feed)
local _, entry = f(v, i)

of, if you like tricks:

local _, _, entry = pcall(ipairs(feed))

But... Why would you do that? You have the feed as a table. You want the first entry of that table:

local entry = feed[1]

Done.


You can just call the result of ipairs(feed) once.

0

精彩评论

暂无评论...
验证码 换一张
取 消