更新「fgu_sync.rake」

This commit is contained in:
chiu 2023-05-26 13:31:36 +00:00
parent 0776ba723d
commit 0eae8b354e
1 changed files with 29 additions and 22 deletions

View File

@ -4,6 +4,7 @@ namespace :fgu_sync do
task :sync_plugins => :environment do
MemberProfile.each do |mp|
staff_id = mp.sid rescue nil
puts mp.id
if !staff_id.nil? && staff_id != ""
sync_fgu_journals(staff_id, mp)
sync_fgu_conference(staff_id, mp)
@ -49,9 +50,9 @@ namespace :fgu_sync do
journal_title = {"en" => dt["journal_title"],"zh_tw" => dt["journal_title"]}
from_to = dt["from_to"].split("-")
from_to[1] = "" if !from_to[1].present?
authors = [dt["author1"],dt["author2"],dt["author3"],dt["author4"]]
authors.delete("")
authors = {"en" => authors.join(", "), "zh_tw" => authors.join(", ")}
all_authors = [dt["author1"],dt["author2"],dt["author3"],dt["author4"]]
all_authors.delete("")
authors = {"en" => all_authors.join(", "), "zh_tw" => all_authors.join(", ")}
note = dt["department"] + " " + dt["country"] + " " + dt["note"]
if !dt["paper_level"].empty?
@ -69,19 +70,24 @@ namespace :fgu_sync do
end
jp = JournalPaper.where(:rss2_id => rss2id).first rescue nil
jp_data = {
:publication_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"),
:authors_translations => authors, :paper_title_translations => paper_title,
:journal_title_translations => journal_title, :vol_no => dt["vol_no"], :issue_no => dt["issue_no"],
:note => note, :form_to_start => from_to[0], :form_to_end => from_to[1]
}
if jp.nil?
jp = JournalPaper.new(:publication_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :journal_title_translations => journal_title, :vol_no => dt["vol_no"], :issue_no => dt["issue_no"], :note => note, :form_to_start => from_to[0], :form_to_end => from_to[1], :member_profile => mp)
jp.journal_levels << level if !level.nil?
jp.journal_paper_type = type if !type.nil?
jp.save
jp = JournalPaper.new(jp_data)
puts "Saving new journal."
else
jp.update_attributes(:publication_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :journal_title_translations => journal_title, :vol_no => dt["vol_no"], :issue_no => dt["issue_no"], :note => note, :form_to_start => from_to[0], :form_to_end => from_to[1])
jp.update_attributes(jp_data)
puts "Updating journal #{jp.id}."
end
jp_mps = MemberProfile.where("tmp_name.zh_tw" => {"$in" => all_authors}).to_a
jp.member_profiles = jp_mps.size==0 ? [mp] : jp_mps
jp.journal_levels << level if !level.nil?
jp.journal_paper_type = type if !type.nil?
jp.save
puts "Updating journal #{jp.id}."
end
end
else
puts "No data found."
@ -112,14 +118,16 @@ namespace :fgu_sync do
note = dt["department"] + " " + dt["note"]
cp = WritingConference.where(:rss2_id => rss2id).first rescue nil
cp_data = {:period_start_date => start_date, :period_end_date => end_date, :rss2_id => rss2id, :year => end_date.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :conference_title_translations => conference_title, :note => note, :location_translations => {"en" => dt["location"], "zh_tw" => dt["location"]}}
if cp.nil?
cp = WritingConference.new(:period_start_date => start_date, :period_end_date => end_date, :rss2_id => rss2id, :year => end_date.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :conference_title_translations => conference_title, :note => note, :member_profile => mp, :location_translations => {"en" => dt["location"], "zh_tw" => dt["location"]})
cp.save
cp = WritingConference.new(cp_data)
puts "Saving new conference."
else
cp.update_attributes(:period_start_date => start_date, :period_end_date => end_date, :rss2_id => rss2id, :year => end_date.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :conference_title_translations => conference_title, :note => note, :location_translations => {"en" => dt["location"], "zh_tw" => dt["location"]})
cp.update_attributes(cp_data)
puts "Updating conference #{cp.id}."
end
cp.member_profile = mp
cp.save
end
else
puts "No data found."
@ -163,19 +171,18 @@ namespace :fgu_sync do
end
book = Book.where(:rss2_id => rss2id).first rescue nil
book_data = {:publish_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :publisher_translations => publisher, :book_title_translations => book_title, :isbn => dt["isbn"], :note => note, :language => dt["language"], :member_profile => mp}
if book.nil?
book = Book.new(:publish_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :publisher_translations => publisher, :book_title_translations => book_title, :isbn => dt["isbn"], :note => note, :language => dt["language"], :member_profile => mp)
book.book_author_types << authortype if !authortype.nil?
book.book_type = type if !type.nil?
book.save
book = Book.new(book_data)
puts "Saving new book."
else
book.update_attributes(:publish_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :publisher_translations => publisher, :book_title_translations => book_title, :isbn => dt["isbn"], :note => note, :language => dt["language"], :member_profile => mp)
book.book_author_types << authortype if !authortype.nil?
book.book_type = type if !type.nil?
book.save
book.update_attributes(book_data)
puts "Updating book #{book.id}."
end
book.book_author_types << authortype if !authortype.nil?
book.book_type = type if !type.nil?
book.member_profile = mp
book.save
end
else
puts "No data found."