- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
试图让我的头脑围绕 Feedzirra 在这里。
我已完成所有设置和所有操作,甚至可以获得结果和更新,但发生了一些奇怪的事情。
我想出了以下代码:
def initialize(feed_url)
@feed_url = feed_url
@rssObject = Feedzirra::Feed.fetch_and_parse(@feed_url)
end
def update_from_feed_continuously()
@rssObject = Feedzirra::Feed.update(@rssObject)
if @rssObject.updated?
puts @rssObject.new_entries.count
else
puts "nil"
end
end
是的,我在上面所做的是从大提要开始,然后只获取更新。我确定我一定是在做一些愚蠢的事情,因为即使我能够获取更新并将它们存储在同一个实例变量中,但在第一次之后,我再也无法获取这些更新了。
显然,发生这种情况是因为我只用更新覆盖了我的实例变量,并丢失了完整的提要对象。
然后我考虑将我的代码更改为:
def update_from_feed_continuously()
feed = Feedzirra::Feed.update(@rssObject)
if feed.updated?
puts feed.new_entries.count
else
puts "nil"
end
end
好吧,我不会覆盖任何东西,这应该是正确的方法吗?
错误,这意味着我注定要始终尝试获取对同一个静态提要对象的更新,因为虽然我获取了一个变量的更新,但我从未真正更新我的“静态” feed 对象”,新添加的项目将附加到我的“feed.new_entries”,因为它们在理论上是新的。
我确定我在这里漏掉了一步,但如果有人能告诉我,我将不胜感激。我已经浏览这段代码几个小时了,但无法掌握它。
显然它应该工作正常,如果我做了类似的事情:
if feed.updated?
puts feed.new_entries.count
@rssObject = initialize(@feed_url)
else
因为这会用一个全新的提要对象重新初始化我的实例变量,并且更新会再次出现。
但这也意味着在那个确切时刻添加的任何新更新都将丢失,以及大量矫枉过正,因为我必须再次加载它。
提前致谢!
最佳答案
如何进行更新对于当前的 API 来说有点违反直觉。这个例子展示了最好的方法:
# I'm using Atom here, but it could be anything. You don't need to know ahead of time.
# It will parse out to the correct format when it updates.
feed_to_update = Feedzirra::Parser::Atom.new
feed_to_update.feed_url = some_stored_feed_url
feed_to_update.etag = some_stored_feed_etag
feed_to_update.last_modified = some_stored_feed_last_modified
last_entry = Feedzirra::Parser::AtomEntry.new
last_entry.url = the_url_of_the_last_entry_for_a_feed
feed_to_update.entries = [last_entry]
updated_feed = Feedzirra::Feed.update(feed_to_update)
updated_feed.updated? # => nil if there is nothing new
updated_feed.new_entries # => [] if nothing new otherwise a collection of feedzirra entries
updated_feed.etag # => same as before if nothing new. although could change with comments added to entries.
updated_feed.last_modified # => same as before if nothing new. although could change with comments added to entries.
基本上,您必须保存四条数据(feed_url、last_modified、etag 和最近条目的 url)。那么当你想做更新你构建一个新的提要对象并调用更新那个。
关于Ruby - Feedzirra 和更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2481285/
试图让我的头脑围绕 Feedzirra 在这里。 我已完成所有设置和所有操作,甚至可以获得结果和更新,但发生了一些奇怪的事情。 我想出了以下代码: def initialize(feed_url)
我真的是 Ruby 的新手(第一天!),我正在努力解决这个问题。我正在尝试结合 Typhoeus 构建一个 rss-parser,因为我正在解析 100 多个提要,也因为我想让它正常工作。 这就是我的
为任何类型的提要提供一个解析器的想法很棒,我希望它对我有用。我一直在尝试让 feedzirra 解析原子提要。具体来说: http://pindancing.blogspot.com/feeds/po
我正在使用 Feedzirra 并尝试按发布日期对提要数据进行哈希排序。我没有收到错误或任何错误,只是没有排序。这是我的 Controller 中的代码: class ClassifiedsContr
我正在尝试安装 feedzirra 但我遇到了麻烦。 当我安装 Feedzirra 时,它会寻找 curb (0.7.18)。 我按照说明在 windows 上安装了 curb >gem instal
我是 Ruby on Rails 的新手。我对 Feed 解析感到很兴奋,但是当我安装 FeedZirra 时,我收到了这个错误。 我使用 Windows 7 和 Ruby 1.8.7。 请帮忙。提前
有没有办法解析提要的自定义元素?不是提要条目,提要的自定义元素。我知道有一种方法可以对条目执行相同的操作。喜欢, Feedzirra::Feed.add_common_feed_entry_eleme
以下代码来自 Feedzirra 的要点,用于从 RSS 提要中获取更新的内容: feed = Feedzirra::Feed.fetch_and_parse(feed_url) feed = Fee
我正在使用 Feedzirra 来解析我的 RSS 提要,它运行良好——在我的初始测试中,它的速度是 Feed Normalizer 的两倍。更重要的是,它有很好的包装器,可以检查提要中的更新条目。当
Bundler could not find compatible versions for gem "builder": In Gemfile: rails (= 3.1.1) depends on
这是我尝试解析的提要结构: title.. http://url … description... Tue, 20 Nov 2012 14:37:30 +0000 sk-SK h
我是一名优秀的程序员,十分优秀!