create a hash rss site list from mongodb

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

No files matched your search

+5 -3
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