新闻追踪与微软办公软件数据交互
1. 新闻追踪应用开发
在新闻追踪方面,我们首先要处理新闻源数据,避免重复数据的插入。以下是处理新闻源数据的代码:
if not (Stories.find_by_title(feed_story.title) or
Stories.find_by_url(feed_story.link) or
Stories.find_by_guid(feed_story.guid))
puts "processing story '#{feed_story.title}' - new"
Stories.new do |new_story|
new_story.title = feed_story.title.gsub(/<[^>]*>/, '') # strip HTML
new_story.guid = feed_story.guid
new_story.sourcename = feed_story.publisher.name if feed_story.publisher.name
new_story.url = feed_story.link
new_story.published_at = feed_story.published
new_story.save
end
else
# do nothing
end
上述代码逻辑为:
1. 检查是否存在具有相同标题、URL 或 GUID 的新闻。
2. 如果不存在,则将该新闻添加到数据库中,并去除
超级会员免费看
订阅专栏 解锁全文
13

被折叠的 条评论
为什么被折叠?



