fix lib: can fetch rss feed from selected categories
This commit is contained in:
parent
9d3ee5b963
commit
813fbc64cd
|
@ -7,8 +7,8 @@ DB_NAME = "production_0"
|
|||
|
||||
# Create a hash rss site list from mongodb
|
||||
db = Mongo::Connection.new("localhost", 27017).db("#{DB_NAME}")
|
||||
SITES = Hash[ db["announcement_feeds"].find().entries.collect {|f| [ f["name"], f["link"] ]} ]
|
||||
CATEGORIES = db["announcement_feeds"].find().entries.map {|f| f["category"] }
|
||||
SITES = Hash[ db["announcement_feeds"].find().entries.collect {|f| [ f["name"], f["link"] ] } ]
|
||||
CATEGORIES = Array(db["announcement_feeds"].find().entries.collect {|f| f["categories"] })
|
||||
|
||||
yesterday = Time.now - 86400
|
||||
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|
|
||||
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,
|
||||
link: item.link, category: category, source: name }
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue