create a hash rss site list from mongodb

This commit is contained in:
thomaschen 2013-11-18 17:38:11 +08:00
parent c807d8a290
commit 3445cb8e69
2 changed files with 7 additions and 5 deletions

View File

@ -8,10 +8,10 @@ defaults: &defaults
development:
<<: *defaults
database: test_site
database: production_0
test:
<<: *defaults
database: test_site
database: production_0
# set these environment variables on your prod server
production:
# host: <%= ENV['MONGOID_HOST'] %>

View File

@ -2,12 +2,14 @@
require 'rss'
require 'mongo'
#create a hash rss site list
SITES = Hash[ AnnouncementFeed.all.map {|feed| [feed.name, feed.link]} ]
#base on your DB
DB_BASE_NAME = "production_0"
#create a hash rss site list from mongodb
db = Mongo::Connection.new("localhost", 27017).db("#{DB_BASE_NAME}")
SITES = Hash[ db["announcement_feeds"].find().entries.collect { |f| [ f["name"], f["link"] ]} ]
yesterday = Time.now - 86400
two_weeks_ago = Time.new - 60 * 60 * 24 * 14
@ -22,7 +24,7 @@ SITES.each do |name, url|
feed.items.each do |item|
category = item.category.to_s.gsub(/\<(\/)*category\>/, '')
if item.pubDate > yesterday
if item.pubDate > two_weeks_ago
recent_feed[item.title.strip] = { date: item.pubDate, description: item.description.gsub("\r\n", '<br/>').strip,
link: item.link, category: category, source: name }
end