Feedzirra 具有多个提要
我已经使用 Feedzirra 一段时间来获取单个提要并解析它们,没有任何问题,但我试图通过它运行两个单独的 feedburner 提要,我知道它们可以单独工作,但运行这两个提要会产生错误。
NoMethodError in Feed entryController#index
undefined method `title' for #<Array:0x1042f9590>
我的模型看起来像这样:
def self.get_feeds
feed_urls = ["feed_1", "feed_2"]
update_from_feeds(feed_urls)
end
def self.update_from_feeds(feed_urls)
feeds = Feedzirra::Feed.fetch_and_parse(feed_urls)
add_entries(feeds.entries)
end
def self.update_from_feeds_continuously(feed_urls, delay_interval = 30.seconds)
feeds = Feedzirra::Feed.fetch_and_parse(feed_urls)
add_entries(feed.entries)
loop do
sleep delay_interval
feeds = Feedzirra::Feed.update(feeds.entries)
add_entries(feeds.new_entries) if feeds.updated?
end
end
private
def self.add_entries(entries)
entries.each do |entry|
unless exists? :guid => entry.id
create!(
:title => entry.title
)
end
end
end
这可能是我做错了,但我找不到任何完整的代码示例或用于解析多个提要的教程,只有 github 页面上的两行代码。
提前致谢!
I've been using Feedzirra for a while to grab single feeds and parse them with no issues but I'm trying to run two separate feedburner feeds through it and I know that they work by themselves but running the both of them is producing an error.
NoMethodError in Feed entryController#index
undefined method `title' for #<Array:0x1042f9590>
My model looks like this:
def self.get_feeds
feed_urls = ["feed_1", "feed_2"]
update_from_feeds(feed_urls)
end
def self.update_from_feeds(feed_urls)
feeds = Feedzirra::Feed.fetch_and_parse(feed_urls)
add_entries(feeds.entries)
end
def self.update_from_feeds_continuously(feed_urls, delay_interval = 30.seconds)
feeds = Feedzirra::Feed.fetch_and_parse(feed_urls)
add_entries(feed.entries)
loop do
sleep delay_interval
feeds = Feedzirra::Feed.update(feeds.entries)
add_entries(feeds.new_entries) if feeds.updated?
end
end
private
def self.add_entries(entries)
entries.each do |entry|
unless exists? :guid => entry.id
create!(
:title => entry.title
)
end
end
end
It's probably something I'm doing wrong but I can't find any full code examples or tutorials for parsing multiple feeds, just the two lines of code on the github page.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当
fetch_and_parse
在update_from_feeds
中返回feeds
时,当传入多个feed时,它是一个数组。因此,每个
被拆分为单独的 feed,而不是 feed 条目。要解决此问题,您可以按如下方式重新定义add_entries
方法中的update_from_feeds
:这假设您始终将多个 feed url 传递给
update_from_feeds
(或数组中的单个 url)When
feeds
is returned inupdate_from_feeds
from thefetch_and_parse
, it is an array when multiple feeds are passed in. As such, theeach
in theadd_entries
method is splitting into individual feeds, not feed entries. To remedy this, you can redefineupdate_from_feeds
as follows:This assumes you will always be passing multiple feed url's to
update_from_feeds
(or a single url in an array)