Fix Sync auto rescue timeout and filter user email for ntu only
This commit is contained in:
parent
52f8e9f1b8
commit
077e98a6d4
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
require 'net/http'
|
require 'net/http'
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
|
require 'timeout'
|
||||||
|
|
||||||
class Admin::ImportDataController < OrbitBackendController
|
class Admin::ImportDataController < OrbitBackendController
|
||||||
# helper Admin::PagePartsHelper
|
# helper Admin::PagePartsHelper
|
||||||
|
@ -483,19 +484,19 @@ end
|
||||||
def sync_conference_data_auto
|
def sync_conference_data_auto
|
||||||
@user = User.all
|
@user = User.all
|
||||||
@user.each do |user|
|
@user.each do |user|
|
||||||
WritingConference.delete_all(conditions:{create_user_id: "#{user.id}"})
|
if user.user_id.present?
|
||||||
# @user = User.find("#{params[:user_id]}")
|
next if !user.email.include? "ntu.edu.tw"
|
||||||
|
|
||||||
# teachers.each do |hash|
|
|
||||||
# if user.sid.present?
|
|
||||||
if user.user_id.present?
|
|
||||||
# ntu_seq = user.sid
|
|
||||||
u_account = user.user_id
|
u_account = user.user_id
|
||||||
conference_xml = Nokogiri::XML( \
|
@conference_xml = nil
|
||||||
# open("http://ann.cc.ntu.edu.tw/Achv/xmlPaper.asp?Seq=#{ntu_seq}&type=C"))
|
begin
|
||||||
open("http://ann.cc.ntu.edu.tw/Achv/xmlData_useMail.asp?item=paper&account=#{u_account}&type=C"))
|
timeout(60) do
|
||||||
#open("http://versatile.management.ntu.edu.tw/publication1/conference/#{ntuseq}.xml"))
|
@conference_xml = Nokogiri::XML( \
|
||||||
@conference_papers = conference_xml.xpath("//Paper").map do |cp_node|
|
open("http://ann.cc.ntu.edu.tw/Achv/xmlData_useMail.asp?item=paper&account=#{u_account}&type=C"))
|
||||||
|
end
|
||||||
|
rescue Timeout::Error
|
||||||
|
next
|
||||||
|
end
|
||||||
|
@conference_papers = @conference_xml.xpath("//Paper").map do |cp_node|
|
||||||
{
|
{
|
||||||
author: (cp_node>"Authors").text,
|
author: (cp_node>"Authors").text,
|
||||||
year: (cp_node>"PublishYear").text,
|
year: (cp_node>"PublishYear").text,
|
||||||
|
@ -508,6 +509,8 @@ end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
if @conference_papers.present?
|
if @conference_papers.present?
|
||||||
|
WritingConference.delete_all(conditions:{create_user_id: user.id})
|
||||||
|
|
||||||
@conference_papers.each do |b|
|
@conference_papers.each do |b|
|
||||||
@conference_paper = WritingConference.new
|
@conference_paper = WritingConference.new
|
||||||
I18n.locale = :zh_tw
|
I18n.locale = :zh_tw
|
||||||
|
@ -545,16 +548,8 @@ end
|
||||||
@conference_paper.save!
|
@conference_paper.save!
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
puts "No conference by Teacher"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
# respond_to do |format|
|
|
||||||
|
|
||||||
# format.html
|
|
||||||
# format.json { render json: {"success"=>true}.to_json}
|
|
||||||
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -562,20 +557,19 @@ end
|
||||||
def sync_journal_paper_data_auto
|
def sync_journal_paper_data_auto
|
||||||
@user = User.all
|
@user = User.all
|
||||||
@user.each do |user|
|
@user.each do |user|
|
||||||
WritingJournal.delete_all(conditions:{create_user_id: "#{user.id}"})
|
|
||||||
# @user = User.find("#{params[:user_id]}")
|
|
||||||
|
|
||||||
# teachers.each do |hash|
|
|
||||||
# if user.sid.present?
|
|
||||||
if user.user_id.present?
|
if user.user_id.present?
|
||||||
next if user.user_id=="chenlin"
|
next if !user.email.include? "ntu.edu.tw"
|
||||||
# ntu_seq = user.sid
|
|
||||||
u_account = user.user_id
|
u_account = user.user_id
|
||||||
paper_xml = Nokogiri::XML( \
|
@paper_xml = nil
|
||||||
#open("http://versatile.management.ntu.edu.tw/publication1/journal/#{ntuseq}.xml"))
|
begin
|
||||||
# open("http://ann.cc.ntu.edu.tw/Achv/xmlPaper.asp?Seq=#{ntu_seq}&type=J"))
|
timeout(60) do
|
||||||
open("http://ann.cc.ntu.edu.tw/Achv/xmlData_useMail.asp?item=paper&account=#{u_account}&type=J"))
|
@paper_xml = Nokogiri::XML( \
|
||||||
@journal_papers = paper_xml.xpath("//Paper").map do |paper_node|
|
open("http://ann.cc.ntu.edu.tw/Achv/xmlData_useMail.asp?item=paper&account=#{u_account}&type=J"))
|
||||||
|
end
|
||||||
|
rescue Timeout::Error
|
||||||
|
next
|
||||||
|
end
|
||||||
|
@journal_papers = @paper_xml.xpath("//Paper").map do |paper_node|
|
||||||
{
|
{
|
||||||
author: (paper_node>"Authors").text,
|
author: (paper_node>"Authors").text,
|
||||||
year: (paper_node>"PublishYear").text,
|
year: (paper_node>"PublishYear").text,
|
||||||
|
@ -591,6 +585,9 @@ def sync_journal_paper_data_auto
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
if @journal_papers.present?
|
if @journal_papers.present?
|
||||||
|
|
||||||
|
WritingJournal.delete_all(conditions:{create_user_id: user.id})
|
||||||
|
|
||||||
@journal_papers.each do |b|
|
@journal_papers.each do |b|
|
||||||
@journal_paper = WritingJournal.new
|
@journal_paper = WritingJournal.new
|
||||||
I18n.locale = :zh_tw
|
I18n.locale = :zh_tw
|
||||||
|
@ -639,18 +636,20 @@ end
|
||||||
def sync_book_data_auto
|
def sync_book_data_auto
|
||||||
@user = User.all
|
@user = User.all
|
||||||
@user.each do |user|
|
@user.each do |user|
|
||||||
WritingBook.delete_all(conditions:{create_user_id: "#{user.id}"})
|
if user.user_id.present?
|
||||||
# @user = User.find("#{params[:user_id]}")
|
next if !user.email.include? "ntu.edu.tw"
|
||||||
|
u_account = user.user_id
|
||||||
|
@books_xml = nil
|
||||||
|
begin
|
||||||
|
timeout(60) do
|
||||||
|
@books_xml = Nokogiri::XML( \
|
||||||
|
open("http://ann.cc.ntu.edu.tw/Achv/xmlData_useMail.asp?item=Book&account=#{u_account}"))
|
||||||
|
end
|
||||||
|
rescue Timeout::Error
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
# teachers.each do |hash|
|
@books = @books_xml.xpath("//Book").map do |book_node|
|
||||||
# if user.sid.present?
|
|
||||||
if user.user_id.present?
|
|
||||||
# ntu_seq = user.sid
|
|
||||||
u_account = user.user_id
|
|
||||||
books_xml = Nokogiri::XML( \
|
|
||||||
# open("http://ann.cc.ntu.edu.tw/Achv/xmlBook.asp?Seq=#{ntu_seq}"))
|
|
||||||
open("http://ann.cc.ntu.edu.tw/Achv/xmlData_useMail.asp?item=Book&account=#{u_account}"))
|
|
||||||
@books = books_xml.xpath("//Book").map do |book_node|
|
|
||||||
{
|
{
|
||||||
author: (book_node>"Authors").text,
|
author: (book_node>"Authors").text,
|
||||||
year: (book_node>"PublishYear").text,
|
year: (book_node>"PublishYear").text,
|
||||||
|
@ -660,7 +659,11 @@ def sync_book_data_auto
|
||||||
book_title: (book_node>"BookTitle").text
|
book_title: (book_node>"BookTitle").text
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
if @books.present?
|
if @books.present?
|
||||||
|
|
||||||
|
WritingBook.delete_all(conditions:{create_user_id: user.id})
|
||||||
|
|
||||||
@books.each do |b|
|
@books.each do |b|
|
||||||
@book = WritingBook.new
|
@book = WritingBook.new
|
||||||
I18n.locale = :zh_tw
|
I18n.locale = :zh_tw
|
||||||
|
@ -681,12 +684,6 @@ def sync_book_data_auto
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# respond_to do |format|
|
|
||||||
|
|
||||||
# format.html
|
|
||||||
# format.json { render json: {"success"=>true}.to_json}
|
|
||||||
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Reference in New Issue