Feedzirra 具有多个提要

发布于 2024-10-01 05:19:57 字数 1115 浏览 0 评论 0原文

我已经使用 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 技术交流群。

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

发布评论

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

评论(1

单挑你×的.吻 2024-10-08 05:19:58

fetch_and_parseupdate_from_feeds中返回feeds时,当传入多个feed时,它是一个数组。因此,每个add_entries 方法中的 被拆分为单独的 feed,而不是 feed 条目。要解决此问题,您可以按如下方式重新定义 update_from_feeds

def self.update_from_feeds(feed_urls)
  feeds = Feedzirra::Feed.fetch_and_parse(feed_urls)
  feeds.each do |feed_url, feed|
    add_entries(feed.entries)
  end
end

这假设您始终将多个 feed url 传递给 update_from_feeds(或数组中的单个 url)

When feeds is returned in update_from_feeds from the fetch_and_parse, it is an array when multiple feeds are passed in. As such, the each in the add_entries method is splitting into individual feeds, not feed entries. To remedy this, you can redefine update_from_feeds as follows:

def self.update_from_feeds(feed_urls)
  feeds = Feedzirra::Feed.fetch_and_parse(feed_urls)
  feeds.each do |feed_url, feed|
    add_entries(feed.entries)
  end
end

This assumes you will always be passing multiple feed url's to update_from_feeds (or a single url in an array)

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