create a hash rss site list from mongodb
This commit is contained in:
parent
c807d8a290
commit
3445cb8e69
|
@ -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'] %>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue