both manual and automatic methods working
Conflicts: config/routes.rb
This commit is contained in:
parent
3b73fab8e2
commit
c3ece3b7af
|
@ -259,6 +259,206 @@ class Admin::ImportDataController < OrbitBackendController
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_conference_data
|
def sync_conference_data
|
||||||
|
@conference_data = WritingConference.where(create_user_id: "#{params[:user_id]}")
|
||||||
|
@conference_data.delete_all
|
||||||
|
@user = User.find("#{params[:user_id]}")
|
||||||
|
|
||||||
|
# teachers.each do |hash|
|
||||||
|
if @user.sid.present?
|
||||||
|
ntu_seq = @user.sid
|
||||||
|
conference_xml = Nokogiri::XML( \
|
||||||
|
open("http://ann.cc.ntu.edu.tw/Achv/xmlPaper.asp?Seq=#{ntu_seq}&type=C"))
|
||||||
|
#open("http://versatile.management.ntu.edu.tw/publication1/conference/#{ntuseq}.xml"))
|
||||||
|
@conference_papers = conference_xml.xpath("//Paper").map do |cp_node|
|
||||||
|
{
|
||||||
|
author: (cp_node>"Authors").text,
|
||||||
|
year: (cp_node>"PublishYear").text,
|
||||||
|
title: (cp_node>"PaperTitle").text,
|
||||||
|
conference: (cp_node>"PublishOn").text,
|
||||||
|
date: Date::MONTHNAMES[(cp_node>"PublishMonth").text.to_i],
|
||||||
|
location: "#{(cp_node>"Country").text} #{(cp_node>"location").text}",
|
||||||
|
conference_title: (cp_node>"PublishOn").text,
|
||||||
|
remarks: (cp_node>"Remarks").text
|
||||||
|
}
|
||||||
|
end
|
||||||
|
if @conference_papers.present?
|
||||||
|
@conference_papers.each do |b|
|
||||||
|
@conference_paper = WritingConference.new
|
||||||
|
I18n.locale = :zh_tw
|
||||||
|
@conference_paper.authors = b[:author]
|
||||||
|
if b[:title].blank?
|
||||||
|
@conference_paper.paper_title = "No Title Present"
|
||||||
|
else
|
||||||
|
@conference_paper.paper_title = b[:title]
|
||||||
|
end
|
||||||
|
if b[:conference_title].blank?
|
||||||
|
@conference_paper.conference_title = "No Title Present"
|
||||||
|
else
|
||||||
|
@conference_paper.conference_title = b[:conference_title]
|
||||||
|
end
|
||||||
|
|
||||||
|
@conference_paper.note = b[:remarks]
|
||||||
|
I18n.locale = :en
|
||||||
|
@conference_paper.authors = b[:author]
|
||||||
|
if b[:title].blank?
|
||||||
|
@conference_paper.paper_title = "No Title Present"
|
||||||
|
else
|
||||||
|
@conference_paper.paper_title = b[:title]
|
||||||
|
end
|
||||||
|
if b[:conference_title].blank?
|
||||||
|
@conference_paper.conference_title = "No Title Present"
|
||||||
|
else
|
||||||
|
@conference_paper.conference_title = b[:conference_title]
|
||||||
|
end
|
||||||
|
@conference_paper.note = b[:remarks]
|
||||||
|
|
||||||
|
@conference_paper.location = b[:location]
|
||||||
|
@conference_paper.year = b[:year]
|
||||||
|
@conference_paper.create_user_id = @user.id
|
||||||
|
|
||||||
|
@conference_paper.save!
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts "No conference by Teacher"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
|
||||||
|
format.html
|
||||||
|
format.json { render json: {"success"=>true}.to_json}
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def sync_journal_paper_data
|
||||||
|
@journal_data = WritingJournal.where(create_user_id: "#{params[:user_id]}")
|
||||||
|
@journal_data.delete_all
|
||||||
|
@user = User.find("#{params[:user_id]}")
|
||||||
|
|
||||||
|
# teachers.each do |hash|
|
||||||
|
if @user.sid.present?
|
||||||
|
ntu_seq = @user.sid
|
||||||
|
paper_xml = Nokogiri::XML( \
|
||||||
|
#open("http://versatile.management.ntu.edu.tw/publication1/journal/#{ntuseq}.xml"))
|
||||||
|
open("http://ann.cc.ntu.edu.tw/Achv/xmlPaper.asp?Seq=#{ntu_seq}&type=J"))
|
||||||
|
@journal_papers = paper_xml.xpath("//Paper").map do |paper_node|
|
||||||
|
{
|
||||||
|
author: (paper_node>"Authors").text,
|
||||||
|
year: (paper_node>"PublishYear").text,
|
||||||
|
title: (paper_node>"PaperTitle").text,
|
||||||
|
journal: (paper_node>"PublishOn").text,
|
||||||
|
volume:(paper_node>"Volume").text,
|
||||||
|
volumeno:(paper_node>"VolumeNo").text,
|
||||||
|
beginpage:(paper_node>"BeginPage").text,
|
||||||
|
endpage:(paper_node>"EndPage").text,
|
||||||
|
subgroup:(paper_node>"subgroup").text,
|
||||||
|
remarks: (paper_node>"Remarks").text,
|
||||||
|
cate: ((paper_node>"subgroup")>"Group").text
|
||||||
|
}
|
||||||
|
end
|
||||||
|
if @journal_papers.present?
|
||||||
|
@journal_papers.each do |b|
|
||||||
|
@journal_paper = WritingJournal.new
|
||||||
|
I18n.locale = :zh_tw
|
||||||
|
@journal_paper.authors = b[:author]
|
||||||
|
|
||||||
|
if b[:title].blank?
|
||||||
|
@journal_paper.paper_title = "No Title Present"
|
||||||
|
else
|
||||||
|
@journal_paper.paper_title = b[:title]
|
||||||
|
end
|
||||||
|
|
||||||
|
@journal_paper.journal_title = b[:journal]
|
||||||
|
@journal_paper.note = b[:remarks]
|
||||||
|
I18n.locale = :en
|
||||||
|
@journal_paper.authors = b[:author]
|
||||||
|
|
||||||
|
if b[:title].blank?
|
||||||
|
@journal_paper.paper_title = "No Title Present"
|
||||||
|
else
|
||||||
|
@journal_paper.paper_title = b[:title]
|
||||||
|
end
|
||||||
|
|
||||||
|
@journal_paper.journal_title = b[:journal]
|
||||||
|
@journal_paper.note = b[:remarks]
|
||||||
|
@journal_paper.year = b[:year]
|
||||||
|
@journal_paper.vol_no = b[:volumeno]
|
||||||
|
@journal_paper.form_to_start = b[:beginpage]
|
||||||
|
@journal_paper.form_to_end = b[:endpage]
|
||||||
|
|
||||||
|
if !b[:cate].blank?
|
||||||
|
@level_type = JournalLevelType.where(:key => b[:cate])
|
||||||
|
if @level_type.present?
|
||||||
|
@journal_paper.journal_level_type_ids = ["#{@level_type.first.id}"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@journal_paper.create_user_id = @user.id
|
||||||
|
@journal_paper.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
|
||||||
|
format.html
|
||||||
|
format.json { render json: {"success"=>true}.to_json}
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def sync_book_data
|
||||||
|
@books_data = WritingBook.where(create_user_id: "#{params[:user_id]}")
|
||||||
|
@books_data.delete_all
|
||||||
|
@user = User.find("#{params[:user_id]}")
|
||||||
|
|
||||||
|
# teachers.each do |hash|
|
||||||
|
if @user.sid.present?
|
||||||
|
ntu_seq = @user.sid
|
||||||
|
books_xml = Nokogiri::XML( \
|
||||||
|
open("http://ann.cc.ntu.edu.tw/Achv/xmlBook.asp?Seq=#{ntu_seq}"))
|
||||||
|
@books = books_xml.xpath("//Book").map do |book_node|
|
||||||
|
{
|
||||||
|
author: (book_node>"Authors").text,
|
||||||
|
year: (book_node>"PublishYear").text,
|
||||||
|
title: (book_node>"DocTitle").text,
|
||||||
|
remarks: (book_node>"Remarks").text,
|
||||||
|
publisher: (book_node>"Publisher").text,
|
||||||
|
book_title: (book_node>"BookTitle").text
|
||||||
|
}
|
||||||
|
end
|
||||||
|
if @books.present?
|
||||||
|
@books.each do |b|
|
||||||
|
@book = WritingBook.new
|
||||||
|
I18n.locale = :zh_tw
|
||||||
|
@book.authors = b[:author]
|
||||||
|
@book.paper_title = b[:title]
|
||||||
|
@book.book_title = b[:book_title]
|
||||||
|
@book.note = b[:remarks]
|
||||||
|
@book.publisher = b[:publisher]
|
||||||
|
I18n.locale = :en
|
||||||
|
@book.authors = b[:author]
|
||||||
|
@book.paper_title = b[:title]
|
||||||
|
@book.book_title = b[:book_title]
|
||||||
|
@book.note = b[:remarks]
|
||||||
|
@book.publisher = b[:publisher]
|
||||||
|
@book.year = b[:year]
|
||||||
|
@book.create_user_id = @user.id
|
||||||
|
@book.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
|
||||||
|
format.html
|
||||||
|
format.json { render json: {"success"=>true}.to_json}
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def sync_conference_data_auto
|
||||||
@user = User.all
|
@user = User.all
|
||||||
@user.each do |user|
|
@user.each do |user|
|
||||||
@conference_data = WritingConference.where(create_user_id: "#{user.id}")
|
@conference_data = WritingConference.where(create_user_id: "#{user.id}")
|
||||||
|
@ -328,7 +528,7 @@ class Admin::ImportDataController < OrbitBackendController
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def sync_journal_paper_data
|
def sync_journal_paper_data_auto
|
||||||
@user = User.all
|
@user = User.all
|
||||||
@user.each do |user|
|
@user.each do |user|
|
||||||
@journal_data = WritingJournal.where(create_user_id: "#{user_id}")
|
@journal_data = WritingJournal.where(create_user_id: "#{user_id}")
|
||||||
|
@ -402,7 +602,7 @@ def sync_journal_paper_data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_book_data
|
def sync_book_data_auto
|
||||||
@user = User.all
|
@user = User.all
|
||||||
@user.each do |user|
|
@user.each do |user|
|
||||||
@books_data = WritingBook.where(create_user_id: "#{user_id}")
|
@books_data = WritingBook.where(create_user_id: "#{user_id}")
|
||||||
|
|
|
@ -8,13 +8,13 @@ defaults: &defaults
|
||||||
|
|
||||||
development:
|
development:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
database: orbit_site_new
|
database: ntu_mb_orbit_2_new
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
database: orbit_site_new
|
database: ntu_mb_orbit_2_new
|
||||||
|
|
||||||
# set these environment variables on your prod server
|
# set these environment variables on your prod server
|
||||||
production:
|
production:
|
||||||
|
@ -24,4 +24,4 @@ production:
|
||||||
# password: <%= ENV['MONGOID_PASSWORD'] %>
|
# password: <%= ENV['MONGOID_PASSWORD'] %>
|
||||||
# database: <%= ENV['MONGOID_DATABASE'] %>
|
# database: <%= ENV['MONGOID_DATABASE'] %>
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
database: orbit_site_new
|
database: ntu_mb_orbit_2_new
|
||||||
|
|
|
@ -219,6 +219,19 @@ Orbit::Application.routes.draw do
|
||||||
get 'restart_server'
|
get 'restart_server'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "import_data/get_teacher_data"
|
||||||
|
get "import_data/get_book_data"
|
||||||
|
get "import_data/get_conference_data"
|
||||||
|
get "import_data/get_journal_paper_data"
|
||||||
|
get "import_data/get_announcement_data"
|
||||||
|
get "import_data/get_page_data"
|
||||||
|
get "import_data/sync_book_data"
|
||||||
|
get "import_data/sync_journal_paper_data"
|
||||||
|
get "import_data/sync_conference_data"
|
||||||
|
get "import_data/sync_book_data_auto"
|
||||||
|
get "import_data/sync_journal_paper_data_auto"
|
||||||
|
get "import_data/sync_conference_data_auto"
|
||||||
|
|
||||||
get "import_data/get_teacher_data"
|
get "import_data/get_teacher_data"
|
||||||
get "import_data/get_book_data"
|
get "import_data/get_book_data"
|
||||||
get "import_data/get_conference_data"
|
get "import_data/get_conference_data"
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
namespace :synchronize do
|
namespace :synchronize do
|
||||||
desc "synchronize tasks"
|
desc "synchronize tasks"
|
||||||
task :data => :environment do
|
task :data => :environment do
|
||||||
p Admin::ImportDataController.new.sync_book_data
|
p Admin::ImportDataController.new.sync_book_data_auto
|
||||||
puts "Book Data Synchronization Complete"
|
puts "Book Data Synchronization Complete"
|
||||||
p Admin::ImportDataController.new.sync_journal_paper_data
|
p Admin::ImportDataController.new.sync_journal_paper_data_auto
|
||||||
puts "Journal Paper Data Synchronization Complete"
|
puts "Journal Paper Data Synchronization Complete"
|
||||||
p Admin::ImportDataController.new.sync_conference_data
|
p Admin::ImportDataController.new.sync_conference_data_auto
|
||||||
puts "Conference Data Synchronization Complete"
|
puts "Conference Data Synchronization Complete"
|
||||||
end
|
end
|
||||||
end
|
end
|
Reference in New Issue