fix lib: can fetch rss feed from selected categories

This commit is contained in:
thomaschen 2013-11-22 17:20:39 +08:00
parent 9d3ee5b963
commit 813fbc64cd
1 changed files with 3 additions and 3 deletions

View File

@ -7,8 +7,8 @@ DB_NAME = "production_0"
# Create a hash rss site list from mongodb # Create a hash rss site list from mongodb
db = Mongo::Connection.new("localhost", 27017).db("#{DB_NAME}") db = Mongo::Connection.new("localhost", 27017).db("#{DB_NAME}")
SITES = Hash[ db["announcement_feeds"].find().entries.collect {|f| [ f["name"], f["link"] ]} ] SITES = Hash[ db["announcement_feeds"].find().entries.collect {|f| [ f["name"], f["link"] ] } ]
CATEGORIES = db["announcement_feeds"].find().entries.map {|f| f["category"] } CATEGORIES = Array(db["announcement_feeds"].find().entries.collect {|f| f["categories"] })
yesterday = Time.now - 86400 yesterday = Time.now - 86400
two_weeks_ago = Time.new - 60 * 60 * 24 * 14 two_weeks_ago = Time.new - 60 * 60 * 24 * 14
@ -24,7 +24,7 @@ SITES.each_with_index do |(name, url), i|
feed.items.each do |item| feed.items.each do |item|
category = item.category.to_s.gsub(/\<(\/)*category\>/, '') category = item.category.to_s.gsub(/\<(\/)*category\>/, '')
if item.pubDate > yesterday && (CATEGORIES[i] == category || CATEGORIES[i] == "all") if item.pubDate > yesterday && CATEGORIES[i].include?(category)
recent_feed[item.title.strip] = { date: item.pubDate, description: item.description.gsub("\r\n", '<br/>').strip, recent_feed[item.title.strip] = { date: item.pubDate, description: item.description.gsub("\r\n", '<br/>').strip,
link: item.link, category: category, source: name } link: item.link, category: category, source: name }
end end