16、新闻追踪与办公自动化:Ruby的应用实践

新闻追踪与办公自动化: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

如果新闻源是缓存的,会打印一条简短消息,说明是缓存内容,并显示最后

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值