Added Automatic Synchronize
Conflicts: Gemfile app/controllers/admin/import_data_controller.rb vendor/built_in_modules/personal_conference/app/models/writing_conference.rb Conflicts: Gemfile app/controllers/admin/import_data_controller.rb
This commit is contained in:
parent
43da2eca79
commit
d226b34de5
|
@ -20,6 +20,7 @@ gem "acts_as_unvlogable"
|
||||||
gem 'youtube_it'
|
gem 'youtube_it'
|
||||||
gem 'gotcha'
|
gem 'gotcha'
|
||||||
gem "geocoder"
|
gem "geocoder"
|
||||||
|
gem 'whenever', :require => false
|
||||||
|
|
||||||
# gem "memcached", "~> 1.4.3"
|
# gem "memcached", "~> 1.4.3"
|
||||||
# gem "memcache-client"
|
# gem "memcache-client"
|
||||||
|
|
|
@ -76,8 +76,8 @@ class Admin::ImportDataController < OrbitBackendController
|
||||||
teachers = User.all
|
teachers = User.all
|
||||||
|
|
||||||
teachers.each do |hash|
|
teachers.each do |hash|
|
||||||
if hash.sid.present?
|
if hash.ntu_seq.present?
|
||||||
ntu_seq = hash.sid
|
ntu_seq = hash.ntu_seq
|
||||||
books_xml = Nokogiri::XML( \
|
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/xmlBook.asp?Seq=#{ntu_seq}"))
|
||||||
@books = books_xml.xpath("//Book").map do |book_node|
|
@books = books_xml.xpath("//Book").map do |book_node|
|
||||||
|
@ -125,8 +125,8 @@ class Admin::ImportDataController < OrbitBackendController
|
||||||
teachers = User.all
|
teachers = User.all
|
||||||
|
|
||||||
teachers.each do |hash|
|
teachers.each do |hash|
|
||||||
if hash.sid.present?
|
if hash.ntu_seq.present?
|
||||||
ntu_seq = hash.sid
|
ntu_seq = hash.ntu_seq
|
||||||
conference_xml = Nokogiri::XML( \
|
conference_xml = Nokogiri::XML( \
|
||||||
open("http://ann.cc.ntu.edu.tw/Achv/xmlPaper.asp?Seq=#{ntu_seq}&type=C"))
|
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"))
|
#open("http://versatile.management.ntu.edu.tw/publication1/conference/#{ntuseq}.xml"))
|
||||||
|
@ -196,8 +196,8 @@ class Admin::ImportDataController < OrbitBackendController
|
||||||
teachers = User.all
|
teachers = User.all
|
||||||
|
|
||||||
teachers.each do |hash|
|
teachers.each do |hash|
|
||||||
if hash.sid.present?
|
if hash.ntu_seq.present?
|
||||||
ntu_seq = hash.sid
|
ntu_seq = hash.ntu_seq
|
||||||
paper_xml = Nokogiri::XML( \
|
paper_xml = Nokogiri::XML( \
|
||||||
#open("http://versatile.management.ntu.edu.tw/publication1/journal/#{ntuseq}.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"))
|
open("http://ann.cc.ntu.edu.tw/Achv/xmlPaper.asp?Seq=#{ntu_seq}&type=J"))
|
||||||
|
@ -259,13 +259,15 @@ class Admin::ImportDataController < OrbitBackendController
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_conference_data
|
def sync_conference_data
|
||||||
@conference_data = WritingConference.where(create_user_id: "#{params[:user_id]}")
|
@user = User.all
|
||||||
|
@user.each do |user|
|
||||||
|
@conference_data = WritingConference.where(create_user_id: "#{user.id}")
|
||||||
@conference_data.delete_all
|
@conference_data.delete_all
|
||||||
@user = User.find("#{params[:user_id]}")
|
# @user = User.find("#{params[:user_id]}")
|
||||||
|
|
||||||
# teachers.each do |hash|
|
# teachers.each do |hash|
|
||||||
if @user.sid.present?
|
if user.sid.present?
|
||||||
ntu_seq = @user.sid
|
ntu_seq = user.sid
|
||||||
conference_xml = Nokogiri::XML( \
|
conference_xml = Nokogiri::XML( \
|
||||||
open("http://ann.cc.ntu.edu.tw/Achv/xmlPaper.asp?Seq=#{ntu_seq}&type=C"))
|
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"))
|
#open("http://versatile.management.ntu.edu.tw/publication1/conference/#{ntuseq}.xml"))
|
||||||
|
@ -314,7 +316,7 @@ class Admin::ImportDataController < OrbitBackendController
|
||||||
|
|
||||||
@conference_paper.location = b[:location]
|
@conference_paper.location = b[:location]
|
||||||
@conference_paper.year = b[:year]
|
@conference_paper.year = b[:year]
|
||||||
@conference_paper.create_user_id = @user.id
|
@conference_paper.create_user_id = user.id
|
||||||
|
|
||||||
@conference_paper.save!
|
@conference_paper.save!
|
||||||
end
|
end
|
||||||
|
@ -322,23 +324,20 @@ class Admin::ImportDataController < OrbitBackendController
|
||||||
puts "No conference by Teacher"
|
puts "No conference by Teacher"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
end
|
||||||
|
|
||||||
format.html
|
|
||||||
format.json { render json: {"success"=>true}.to_json}
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def sync_journal_paper_data
|
def sync_journal_paper_data
|
||||||
@journal_data = WritingJournal.where(create_user_id: "#{params[:user_id]}")
|
@user = User.all
|
||||||
|
@user.each do |user|
|
||||||
|
@journal_data = WritingJournal.where(create_user_id: "#{user_id}")
|
||||||
@journal_data.delete_all
|
@journal_data.delete_all
|
||||||
@user = User.find("#{params[:user_id]}")
|
# @user = User.find("#{params[:user_id]}")
|
||||||
|
|
||||||
# teachers.each do |hash|
|
# teachers.each do |hash|
|
||||||
if @user.sid.present?
|
if user.sid.present?
|
||||||
ntu_seq = @user.sid
|
ntu_seq = user.sid
|
||||||
paper_xml = Nokogiri::XML( \
|
paper_xml = Nokogiri::XML( \
|
||||||
#open("http://versatile.management.ntu.edu.tw/publication1/journal/#{ntuseq}.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"))
|
open("http://ann.cc.ntu.edu.tw/Achv/xmlPaper.asp?Seq=#{ntu_seq}&type=J"))
|
||||||
|
@ -394,28 +393,25 @@ class Admin::ImportDataController < OrbitBackendController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@journal_paper.create_user_id = @user.id
|
@journal_paper.create_user_id = user.id
|
||||||
@journal_paper.save!
|
@journal_paper.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
|
||||||
|
|
||||||
format.html
|
|
||||||
format.json { render json: {"success"=>true}.to_json}
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def sync_book_data
|
def sync_book_data
|
||||||
@books_data = WritingBook.where(create_user_id: "#{params[:user_id]}")
|
@user = User.all
|
||||||
|
@user.each do |user|
|
||||||
|
@books_data = WritingBook.where(create_user_id: "#{user_id}")
|
||||||
@books_data.delete_all
|
@books_data.delete_all
|
||||||
@user = User.find("#{params[:user_id]}")
|
# @user = User.find("#{params[:user_id]}")
|
||||||
|
|
||||||
# teachers.each do |hash|
|
# teachers.each do |hash|
|
||||||
if @user.sid.present?
|
if user.sid.present?
|
||||||
ntu_seq = @user.sid
|
ntu_seq = user.sid
|
||||||
books_xml = Nokogiri::XML( \
|
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/xmlBook.asp?Seq=#{ntu_seq}"))
|
||||||
@books = books_xml.xpath("//Book").map do |book_node|
|
@books = books_xml.xpath("//Book").map do |book_node|
|
||||||
|
@ -444,18 +440,13 @@ def sync_book_data
|
||||||
@book.note = b[:remarks]
|
@book.note = b[:remarks]
|
||||||
@book.publisher = b[:publisher]
|
@book.publisher = b[:publisher]
|
||||||
@book.year = b[:year]
|
@book.year = b[:year]
|
||||||
@book.create_user_id = @user.id
|
@book.create_user_id = user.id
|
||||||
@book.save
|
@book.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
|
||||||
|
|
||||||
format.html
|
|
||||||
format.json { render json: {"success"=>true}.to_json}
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def get_announcement_data
|
def get_announcement_data
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Use this file to easily define all of your cron jobs.
|
||||||
|
#
|
||||||
|
# It's helpful, but not entirely necessary to understand cron before proceeding.
|
||||||
|
# http://en.wikipedia.org/wiki/Cron
|
||||||
|
|
||||||
|
# Example:
|
||||||
|
#
|
||||||
|
# set :output, "/path/to/my/cron_log.log"
|
||||||
|
#
|
||||||
|
every 1.day, :at => '11:00 pm' do
|
||||||
|
# command "/usr/bin/some_great_command"
|
||||||
|
# runner "MyModel.some_method"
|
||||||
|
rake "rake synchronize:data"
|
||||||
|
end
|
||||||
|
#
|
||||||
|
# every 4.days do
|
||||||
|
# runner "AnotherModel.prune_old_records"
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Learn more: http://github.com/javan/whenever
|
|
@ -0,0 +1,12 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
namespace :synchronize do
|
||||||
|
desc "synchronize tasks"
|
||||||
|
task :data => :environment do
|
||||||
|
p Admin::ImportDataController.new.sync_book_data
|
||||||
|
puts "Book Data Synchronization Complete"
|
||||||
|
p Admin::ImportDataController.new.sync_journal_paper_data
|
||||||
|
puts "Journal Paper Data Synchronization Complete"
|
||||||
|
p Admin::ImportDataController.new.sync_conference_data
|
||||||
|
puts "Conference Data Synchronization Complete"
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue