新闻追踪与办公自动化:Ruby的应用实践
1. 新闻追踪报告应用创建
1.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
如果新闻源是缓存的,会打印一条简短消息,说明是缓存内容,并显示最后
超级会员免费看
订阅专栏 解锁全文
34

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



