简体   繁体   English

识别RSS源是否已更新的最佳方法

[英]Best way to identify if an RSS feed is Updated

I am trying to build a simple RSS feed reader in RoR as my first project. 我正在尝试在RoR中构建一个简单的RSS feed阅读器,这是我的第一个项目。 When trying to find the best way to do so, I keep reading about using conditional get to only get the feed if it has been modified since the last update. 当试图找到最好的方法时,我不断阅读有关使用条件获取仅在自上次更新以来对其进行了修改的情况下获取提要的信息。

Assuming that the feed that I am getting has this information in the header, how do I only accomplish this? 假设我获取的提要在标头中包含此信息,我如何仅完成此操作?

Sun, 19 Nov 2017 05:21:56 +0800 太阳,2017年11月19日05:21:56 +0800

Currently, I do something similar to the following: 目前,我正在执行以下操作:

xml = HTTParty.get(url).body feed = Feedjira.parse(xml) xml = HTTParty.get(url).body feed = Feedjira.parse(xml)

** I am pretty new so any other suggestion or material that might help will be appritiated. **我很新,因此可能会提出任何其他建议或材料。

to see if the RSS is updated you should maintain and check the headers like Etag and Last-Modified 要查看RSS是否已更新,您应该维护并检查标题,例如EtagLast-Modified

So once you read the RSS feed first time extract these headers and maintain on reader side. 因此,一旦您第一次阅读RSS feed,请提取这些标头并保留在阅读器端。 And for subsequent request just do comparison for these tags, and if changed do parse the feed. 对于后续请求,只需对这些标记进行比较,如果更改,则解析提要。

response = HTTParty.get(url)
headers = response.headers
last_modified = headers['Last-Modified']
etag = headers['Etag']
body = response.body
feed = Feedjira.parse(body) if(stored_last_modified != last_modified or etag != stored_etag)

might be old but good to read this 可能是旧的,但良好的阅读

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM