Fix ntu_ga sites aggregate
This commit is contained in:
parent
6d6650042e
commit
22b95d4b22
|
@ -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", '<br/>').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
|
||||
|
|
Loading…
Reference in New Issue