Changes for NTU Student Affairs

This commit is contained in:
chris 2013-03-27 20:40:59 +08:00
parent d766eea9f4
commit 09bb318d6a
7 changed files with 208 additions and 23 deletions

View File

@ -1,6 +1,17 @@
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html class="<%= I18n.locale.to_s %>"> <html class="<%= I18n.locale.to_s %>">
<head> <head>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-39393439-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<meta charset="utf-8"> <meta charset="utf-8">
<%= page_title(@item).html_safe %> <%= page_title(@item).html_safe %>
<link rel="shortcut icon" href="<%= asset_path "ncculogo.ico" %>"> <link rel="shortcut icon" href="<%= asset_path "ncculogo.ico" %>">

View File

@ -3,7 +3,6 @@
<% end %> <% end %>
<ul> <ul>
<li>總務處電話:<a href="tel:+886229393091">02-29393091</a></li> <li>學務處電話:<a href="tel:+886-2-3366-2995~2997">+886-2-3366-2995~2997</a></li>
<li>總務處傳真02-29379611</li> <li>學務處傳真:+886-2-2391-9095</li>
<li>總務處單一窗口 李梅森專員:<a href="tel:+886233662233">02-33662233</a></li>
</ul> </ul>

View File

@ -4,10 +4,10 @@ en:
bulletin: Bulletin bulletin: Bulletin
contact: Contact contact: Contact
copyright: Copyright copyright: Copyright
copyright_text: Thisi University © All RIGHTS RESERVED. copyright_text: Copyright© 2008 National Taiwan University ALL RIGHTS RESERVED
copyright_orbit: Powered by RulingDigital copyright_orbit: Powered by RulingDigital
home: Home home: Home
language: Language language: Language
location: Location location: Location
location_description: '<h3>OFFICE OF GENERAL AFFAIRS, NTU</h3>No. 1, Sec. 4, Roosevelt Road, Taipei, 10617 Taiwan (R.O.C)' location_description: '<h3>National Taiwan University</h3>No. 1, Sec. 4, Roosevelt Road, Taipei, 10617 Taiwan (R.O.C)'
page: Page page: Page

View File

@ -4,7 +4,7 @@ zh_tw:
bulletin: 公告 bulletin: 公告
contact: 聯絡資訊 contact: 聯絡資訊
copyright: 著作權宣告 copyright: 著作權宣告
copyright_text: 本網站著作權屬於本大學。 copyright_text: 本網站著作權屬於國立臺灣大學 學生事務處
copyright_orbit: 銳綸數位建置 copyright_orbit: 銳綸數位建置
home: 首頁 home: 首頁
language: 語言 language: 語言

99
lib/rss_ntu_job.rb Normal file
View File

@ -0,0 +1,99 @@
# encoding: utf-8
# encoding: utf-8
require 'rss'
require 'mongo'
AUTHORS = %w[ 學生事務處-學生住宿服務組
-
-
-
-
-
-
-
-
-]
DB_BASE_NAME = "site"
all = []
continue = true
i = 1
yesterday = Time.now - 86400
while continue do
open("http://ann.cc.ntu.edu.tw/asp/rss.asp?page=#{i}") do |rss|
feed = RSS::Parser.parse(rss.read.encode('utf-8', 'big5', invalid: :replace, undef: :replace, replace: '').gsub('<pubDate>Wes,', '<pubDate>Wed,').gsub(/(encoding=\"big5\")/, 'encoding="utf-8"'))
feed.items.each do |item|
if item.pubDate > yesterday
if AUTHORS.include?(item.author)
author = item.author.strip
category = item.category.to_s.gsub(/\<(\/)*category\>/, '')
all << {title: item.title.strip, author: author, link: item.link.strip, date: item.pubDate, category: category, description: item.description.gsub("\r\n", '<br/>').strip}
end
else
continue = false
break
end
end
end
i += 1
end
# Get corresponding category_id or create a new one
def get_category_id(category, categories, coll_cat)
if categories.keys.include? "rss_#{category}"
[categories["rss_#{category}"], categories]
else
cat = {
_type: "BulletinCategory",
key: "rss_#{category}",
disable: false,
title: {:zh_tw => category},
created_at: Time.now,
updated_at: Time.now
}
categories["rss_#{category}"] = result = coll_cat.save(cat)
[result, categories]
end
end
# Get categories and id based on a given site number
def get_mongo_and_categories(site_number="0")
db = Mongo::Connection.new("localhost", 27017).db("#{DB_BASE_NAME}_#{site_number}")
coll_bulletin = db["bulletins"]
coll_cat = db["bulletin_categories"]
categories = coll_cat.find().to_a.inject({}) do |categories, category|
categories[category['key']] = category['_id']
categories
end
[categories, coll_bulletin, coll_cat]
end
# Get categories
categories, coll_bulletin, coll_cat = get_mongo_and_categories
all.each do |bul| # Loop through all the items
category_id, categories = get_category_id(bul[:category], categories, coll_cat)
unless coll_bulletin.find_one(rss_link: bul[:link])
bulletin = { _type: "Bulletin",
postdate: bul[:date],
created_at: bul[:date],
updated_at: bul[:date],
is_checked: true,
is_pending: false,
is_rejected: false,
bulletin_category_id: category_id,
title: {:zh_tw => bul[:title]},
text: {:zh_tw => bul[:description]},
available_for_zh_tw: true,
rss_link: bul[:link] }
coll_bulletin.save(bulletin)
end
end

91
lib/rss_ntu_migrate.rb Normal file
View File

@ -0,0 +1,91 @@
# encoding: utf-8
require 'rss'
require 'mongo'
AUTHORS = %w[ 學生事務處-學生住宿服務組
-
-
-
-
-
-
-
-
-]
DB_BASE_NAME = "site"
all = []
continue = true
i = 1
while continue do
open("http://ann.cc.ntu.edu.tw/asp/rss.asp?page=#{i}") do |rss|
feed = RSS::Parser.parse(rss.read.encode('utf-8', 'big5', invalid: :replace, undef: :replace, replace: '').gsub('<pubDate>Wes,', '<pubDate>Wed,').gsub(/(encoding=\"big5\")/, 'encoding="utf-8"'))
feed.items.size
feed.items.each do |item|
if AUTHORS.include?(item.author)
author = item.author.strip
category = item.category.to_s.gsub(/\<(\/)*category\>/, '')
all << {title: item.title.strip, author: author, link: item.link.strip, date: item.pubDate, category: category, description: item.description.gsub("\r\n", '<br/>').strip}
end
end
continue = false if feed.items.size < 100
end
i += 1
end
# Get corresponding category_id or create a new one
def get_category_id(category, categories, coll_cat)
if categories.keys.include? "rss_#{category}"
[categories["rss_#{category}"], categories]
else
cat = {
_type: "BulletinCategory",
key: "rss_#{category}",
disable: false,
title: {:zh_tw => category},
created_at: Time.now,
updated_at: Time.now
}
categories["rss_#{category}"] = result = coll_cat.save(cat)
[result, categories]
end
end
# Get categories and id based on a given site number
def get_mongo_and_categories(site_number="0")
db = Mongo::Connection.new("localhost", 27017).db("#{DB_BASE_NAME}_#{site_number}")
coll_bulletin = db["bulletins"]
coll_cat = db["bulletin_categories"]
categories = coll_cat.find().to_a.inject({}) do |categories, category|
categories[category['key']] = category['_id']
categories
end
[categories, coll_bulletin, coll_cat]
end
# Get categories
categories, coll_bulletin, coll_cat = get_mongo_and_categories
all.each do |bul| # Loop through all the items
category_id, categories = get_category_id(bul[:category], categories, coll_cat)
unless coll_bulletin.find_one(rss_link: bul[:link])
bulletin = { _type: "Bulletin",
postdate: bul[:date],
created_at: bul[:date],
updated_at: bul[:date],
is_checked: true,
is_pending: false,
is_rejected: false,
bulletin_category_id: category_id,
title: {:zh_tw => bul[:title]},
text: {:zh_tw => bul[:description]},
available_for_zh_tw: true,
rss_link: bul[:link] }
coll_bulletin.save(bulletin)
end
end

View File

@ -26,18 +26,12 @@ namespace :mongo_files do
IMAGE_UPLOADER_MODELS = %w[ad_image bulletin image site] IMAGE_UPLOADER_MODELS = %w[ad_image bulletin image site]
# ad_banner
# bulletin
# design
# site
task :clean => :environment do task :clean => :environment do
@files = Mongoid.database['fs.files'] @files = Mongoid.database['fs.files']
@chunks = Mongoid.database['fs.chunks'] @chunks = Mongoid.database['fs.chunks']
clean_duplicates clean_duplicates
clean_unused clean_unused
remove_objects remove_objects
# remove_unlinked
end end
# Remove unused files from db # Remove unused files from db
@ -81,7 +75,7 @@ namespace :mongo_files do
# Remove duplicate files from db # Remove duplicate files from db
def clean_duplicates def clean_duplicates
p "# of files in db: #{@files.count}" p "# of files in db: #{@files.count}"
file_hash = @files.find().inject({}) do |db_files, file| file_hash = @files.find().sort({uploadDate: -1}).inject({}) do |db_files, file|
name = file['filename'] name = file['filename']
if db_files[name] if db_files[name]
db_files[name] += [file['_id']] db_files[name] += [file['_id']]
@ -119,17 +113,8 @@ namespace :mongo_files do
Mongoid.database['writing_journals'].remove() Mongoid.database['writing_journals'].remove()
Mongoid.database['writing_journal_files'].remove() Mongoid.database['writing_journal_files'].remove()
# Destroy bulletins, bulletin_files and bulletin_links
Bulletin.excludes(create_user_id: nil).destroy
BulletinFile.destroy_all
BulletinLink.destroy_all
# Destroy gallery_albums and gallery_images
Mongoid.database['gallery_albums'].remove()
Mongoid.database['gallery_images'].remove()
db_array = @files.find().inject([]) do |db_files, file| db_array = @files.find().inject([]) do |db_files, file|
db_files << file['filename'] if file['filename'] =~ /writing_journal_file|news_bulletin_file|bulletin_file|gallery_image|image\/image/ db_files << file['filename'] if file['filename'] =~ /writing_journal_file|news_bulletin_file|image\/image/
db_files db_files
end end
p db_array.size p db_array.size