Added Automatic Synchronize
This commit is contained in:
parent
7519533107
commit
e22cbbd029
1
Gemfile
1
Gemfile
|
@ -18,6 +18,7 @@ gem 'kaminari'
|
|||
gem 'time_difference'
|
||||
gem "acts_as_unvlogable"
|
||||
gem 'youtube_it'
|
||||
gem 'whenever', :require => false
|
||||
|
||||
# gem "memcached", "~> 1.4.3"
|
||||
# gem "memcache-client"
|
||||
|
|
|
@ -259,13 +259,15 @@ class Admin::ImportDataController < OrbitBackendController
|
|||
end
|
||||
|
||||
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
|
||||
@user = User.find("#{params[:user_id]}")
|
||||
# @user = User.find("#{params[:user_id]}")
|
||||
|
||||
# teachers.each do |hash|
|
||||
if @user.sid.present?
|
||||
ntu_seq = @user.sid
|
||||
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"))
|
||||
|
@ -314,7 +316,7 @@ class Admin::ImportDataController < OrbitBackendController
|
|||
|
||||
@conference_paper.location = b[:location]
|
||||
@conference_paper.year = b[:year]
|
||||
@conference_paper.create_user_id = @user.id
|
||||
@conference_paper.create_user_id = user.id
|
||||
|
||||
@conference_paper.save!
|
||||
end
|
||||
|
@ -322,23 +324,20 @@ class Admin::ImportDataController < OrbitBackendController
|
|||
puts "No conference by Teacher"
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
|
||||
format.html
|
||||
format.json { render json: {"success"=>true}.to_json}
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def sync_journal_paper_data
|
||||
@journal_data = WritingJournal.where(create_user_id: "#{params[:user_id]}")
|
||||
def sync_journal_paper_data
|
||||
@user = User.all
|
||||
@user.each do |user|
|
||||
@journal_data = WritingJournal.where(create_user_id: "#{user_id}")
|
||||
@journal_data.delete_all
|
||||
@user = User.find("#{params[:user_id]}")
|
||||
# @user = User.find("#{params[:user_id]}")
|
||||
|
||||
# teachers.each do |hash|
|
||||
if @user.sid.present?
|
||||
ntu_seq = @user.sid
|
||||
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"))
|
||||
|
@ -394,28 +393,25 @@ class Admin::ImportDataController < OrbitBackendController
|
|||
end
|
||||
end
|
||||
|
||||
@journal_paper.create_user_id = @user.id
|
||||
@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
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
@user = User.find("#{params[:user_id]}")
|
||||
# @user = User.find("#{params[:user_id]}")
|
||||
|
||||
# teachers.each do |hash|
|
||||
if @user.sid.present?
|
||||
ntu_seq = @user.sid
|
||||
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|
|
||||
|
@ -444,18 +440,13 @@ def sync_book_data
|
|||
@book.note = b[:remarks]
|
||||
@book.publisher = b[:publisher]
|
||||
@book.year = b[:year]
|
||||
@book.create_user_id = @user.id
|
||||
@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
|
||||
end
|
||||
|
||||
|
||||
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
|
|
@ -91,7 +91,6 @@ class WritingConference
|
|||
title << "#{period_start_date}-#{period_end_date}" if (self.period_start_date.present? && self.period_end_date.present?)
|
||||
# title << "(#{self.conference_paper_types.collect{|x| x.title}.join(', ')})"
|
||||
title.join(', ')
|
||||
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
Loading…
Reference in New Issue