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"
|
DB_BASE_NAME = "production_0"
|
||||||
|
|
||||||
yesterday = Time.now - 86400
|
yesterday = Time.now - 86400
|
||||||
|
two_weeks_ago = Time.new - 60 * 60 * 24 * 14
|
||||||
|
|
||||||
recent_feed = {}
|
recent_feed = {}
|
||||||
|
|
||||||
SITES.each do |name, url|
|
SITES.each do |name, url|
|
||||||
|
@ -27,7 +29,8 @@ SITES.each do |name, url|
|
||||||
|
|
||||||
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
|
|
||||||
|
if item.pubDate > two_weeks_ago
|
||||||
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 }
|
link: item.link, category: category }
|
||||||
end
|
end
|
||||||
|
@ -66,31 +69,28 @@ def get_mongo_and_categories
|
||||||
[categories, coll_bulletin, coll_cat]
|
[categories, coll_bulletin, coll_cat]
|
||||||
end
|
end
|
||||||
|
|
||||||
recent_feed.each do |title, content|
|
recent_feed.each do |title, bulletin|
|
||||||
|
|
||||||
categories, coll_bulletin, coll_cat = get_mongo_and_categories
|
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|
|
unless coll_bulletin.find_one(rss_link: bulletin[:link])
|
||||||
# category_id, categories = get_category_id(bulletin[:category], categories, coll_cat)
|
bulletin = { _type: "Bulletin",
|
||||||
# unless coll_bulletin.find_one(rss_link: bulletin[:link])
|
postdate: bulletin[:date],
|
||||||
# bulletin = { _type: "Bulletin",
|
created_at: bulletin[:date],
|
||||||
# postdate: bulletin[:date],
|
updated_at: bulletin[:date],
|
||||||
# created_at: bulletin[:date],
|
is_checked: true,
|
||||||
# updated_at: bulletin[:date],
|
is_pending: false,
|
||||||
# is_checked: true,
|
is_rejected: false,
|
||||||
# is_pending: false,
|
bulletin_category_id: category_id,
|
||||||
# is_rejected: false,
|
title: {:zh_tw => title},
|
||||||
# bulletin_category_id: category_id,
|
text: {:zh_tw => bulletin[:description]},
|
||||||
# title: {:zh_tw => bulletin[:title]},
|
available_for_zh_tw: true,
|
||||||
# text: {:zh_tw => bulletin[:description]},
|
rss_link: bulletin[:link],
|
||||||
# available_for_zh_tw: true,
|
is_top: false,
|
||||||
# rss_link: bulletin[:link],
|
is_hot: false,
|
||||||
# is_top: false,
|
is_hidden: false }
|
||||||
# is_hot: false,
|
|
||||||
# is_hidden: false }
|
|
||||||
|
|
||||||
# puts bulletin
|
coll_bulletin.save(bulletin)
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue