diff --git a/vendor/built_in_modules/announcement/lib/rss_ntu_ga_aggregate.rb b/vendor/built_in_modules/announcement/lib/rss_ntu_ga_aggregate.rb index 4afa93a10..c15751801 100644 --- a/vendor/built_in_modules/announcement/lib/rss_ntu_ga_aggregate.rb +++ b/vendor/built_in_modules/announcement/lib/rss_ntu_ga_aggregate.rb @@ -17,6 +17,8 @@ SITES = { "總務長室暨總務處秘書室" => "sec.ga.ntu.edu.tw", DB_BASE_NAME = "production_0" yesterday = Time.now - 86400 +two_weeks_ago = Time.new - 60 * 60 * 24 * 14 + recent_feed = {} SITES.each do |name, url| @@ -27,7 +29,8 @@ 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 } end @@ -66,31 +69,28 @@ def get_mongo_and_categories [categories, coll_bulletin, coll_cat] end -recent_feed.each do |title, content| +recent_feed.each do |title, bulletin| categories, coll_bulletin, coll_cat = get_mongo_and_categories + category_id, categories = get_category_id(bulletin[:category], categories, coll_cat) - content.each_value do |bulletin| - # category_id, categories = get_category_id(bulletin[:category], categories, coll_cat) - # unless coll_bulletin.find_one(rss_link: bulletin[:link]) - # bulletin = { _type: "Bulletin", - # postdate: bulletin[:date], - # created_at: bulletin[:date], - # updated_at: bulletin[:date], - # is_checked: true, - # is_pending: false, - # is_rejected: false, - # bulletin_category_id: category_id, - # title: {:zh_tw => bulletin[:title]}, - # text: {:zh_tw => bulletin[:description]}, - # available_for_zh_tw: true, - # rss_link: bulletin[:link], - # is_top: false, - # is_hot: false, - # is_hidden: false } + unless coll_bulletin.find_one(rss_link: bulletin[:link]) + bulletin = { _type: "Bulletin", + postdate: bulletin[:date], + created_at: bulletin[:date], + updated_at: bulletin[:date], + is_checked: true, + is_pending: false, + is_rejected: false, + bulletin_category_id: category_id, + title: {:zh_tw => title}, + text: {:zh_tw => bulletin[:description]}, + available_for_zh_tw: true, + rss_link: bulletin[:link], + is_top: false, + is_hot: false, + is_hidden: false } - # puts bulletin - # end + coll_bulletin.save(bulletin) end - end