From 3445cb8e69d33c93e59b2b45f70f52bb2312356f Mon Sep 17 00:00:00 2001 From: thomaschen <99703040@nccu.edu.tw> Date: Mon, 18 Nov 2013 17:38:11 +0800 Subject: [PATCH] create a hash rss site list from mongodb --- config/mongoid.yml | 4 ++-- vendor/built_in_modules/feed/lib/rss_dynamic.rb | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/config/mongoid.yml b/config/mongoid.yml index b42849e50..4a8b2c3a3 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -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'] %> diff --git a/vendor/built_in_modules/feed/lib/rss_dynamic.rb b/vendor/built_in_modules/feed/lib/rss_dynamic.rb index 81caa57af..1c6ca849f 100644 --- a/vendor/built_in_modules/feed/lib/rss_dynamic.rb +++ b/vendor/built_in_modules/feed/lib/rss_dynamic.rb @@ -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", '
').strip, link: item.link, category: category, source: name } end