Compare commits
3
Commits
0917_ntu_mb
...
cron
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0aad7ecb7 | ||
|
|
58c652bfba | ||
|
|
e22cbbd029 |
No files matched your search
@@ -18,6 +18,7 @@ gem 'kaminari'
|
|||||||
gem 'time_difference'
|
gem 'time_difference'
|
||||||
gem "acts_as_unvlogable"
|
gem "acts_as_unvlogable"
|
||||||
gem 'youtube_it'
|
gem 'youtube_it'
|
||||||
|
gem 'whenever', :require => false
|
||||||
|
|
||||||
# gem "memcached", "~> 1.4.3"
|
# gem "memcached", "~> 1.4.3"
|
||||||
# gem "memcache-client"
|
# gem "memcache-client"
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ require 'net/http'
|
|||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
|
|
||||||
class Admin::ImportDataController < OrbitBackendController
|
class Admin::ImportDataController < OrbitBackendController
|
||||||
helper Admin::PagePartsHelper
|
# helper Admin::PagePartsHelper
|
||||||
include Admin::FrontendWidgetInterface
|
# include Admin::FrontendWidgetInterface
|
||||||
|
|
||||||
def get_teacher_data
|
def get_teacher_data
|
||||||
uri = URI("https://localhost:8000/teachers.xml")
|
uri = URI("https://localhost:8000/teachers.xml")
|
||||||
@@ -258,7 +258,7 @@ class Admin::ImportDataController < OrbitBackendController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_conference_data
|
def sync_conference_data
|
||||||
@conference_data = WritingConference.where(create_user_id: "#{params[:user_id]}")
|
@conference_data = WritingConference.where(create_user_id: "#{params[:user_id]}")
|
||||||
@conference_data.delete_all
|
@conference_data.delete_all
|
||||||
@user = User.find("#{params[:user_id]}")
|
@user = User.find("#{params[:user_id]}")
|
||||||
@@ -455,9 +455,200 @@ def sync_book_data
|
|||||||
format.json { render json: {"success"=>true}.to_json}
|
format.json { render json: {"success"=>true}.to_json}
|
||||||
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def sync_conference_data_auto
|
||||||
|
@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]}")
|
||||||
|
|
||||||
|
# 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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def sync_journal_paper_data_auto
|
||||||
|
@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]}")
|
||||||
|
|
||||||
|
# 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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def sync_book_data_auto
|
||||||
|
@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]}")
|
||||||
|
|
||||||
|
# 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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def get_announcement_data
|
def get_announcement_data
|
||||||
uri = URI("https://localhost:8000/announcements.xml")
|
uri = URI("https://localhost:8000/announcements.xml")
|
||||||
|
|
||||||
@@ -502,72 +693,72 @@ def sync_book_data
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_page_data
|
# def get_page_data
|
||||||
f = File.open("/home/rwub/orbit-db/ntu_mb/pages/management_pages.xml")
|
# f = File.open("/home/rwub/orbit-db/ntu_mb/pages/management_pages.xml")
|
||||||
page_xml = Nokogiri::XML(f)
|
# page_xml = Nokogiri::XML(f)
|
||||||
#open("http://versatile.management.ntu.edu.tw/publication1/conference/#{ntuseq}.xml"))
|
# #open("http://versatile.management.ntu.edu.tw/publication1/conference/#{ntuseq}.xml"))
|
||||||
@pages = page_xml.xpath("//management-page").map do |cp_node|
|
# @pages = page_xml.xpath("//management-page").map do |cp_node|
|
||||||
{
|
# {
|
||||||
menu_title: (cp_node>"menu-title").text,
|
# menu_title: (cp_node>"menu-title").text,
|
||||||
content: (cp_node>"content").text
|
# content: (cp_node>"content").text
|
||||||
}
|
# }
|
||||||
end
|
# end
|
||||||
|
|
||||||
if @pages.present?
|
# if @pages.present?
|
||||||
@i=0
|
# @i=0
|
||||||
@pages.each do |b|
|
# @pages.each do |b|
|
||||||
|
|
||||||
get_variables_for_new
|
# get_variables_for_new
|
||||||
@page = Page.new
|
# @page = Page.new
|
||||||
|
|
||||||
@page.parent = "4f45f3b9e9d02c5db900005d"
|
# @page.parent = "4f45f3b9e9d02c5db900005d"
|
||||||
@page.design = "50ac424983e75219d2000021"
|
# @page.design = "50ac424983e75219d2000021"
|
||||||
@page.theme_id = "50ac424a83e75219d2000025"
|
# @page.theme_id = "50ac424a83e75219d2000025"
|
||||||
@page.menu_enabled_for= ["en", "zh_tw", ""]
|
# @page.menu_enabled_for= ["en", "zh_tw", ""]
|
||||||
@page.enabled_for= ["en", "zh_tw", ""]
|
# @page.enabled_for= ["en", "zh_tw", ""]
|
||||||
@page.is_published = false
|
# @page.is_published = false
|
||||||
if b[:menu_title].blank?
|
# if b[:menu_title].blank?
|
||||||
@page.title = 'No Title Present'
|
# @page.title = 'No Title Present'
|
||||||
@i += 1
|
# @i += 1
|
||||||
@page.name = "#{@i}Page"
|
# @page.name = "#{@i}Page"
|
||||||
else
|
# else
|
||||||
@i += 1
|
# @i += 1
|
||||||
@page.title = b[:menu_title]
|
# @page.title = b[:menu_title]
|
||||||
@page.name = "#{@i}Page"
|
# @page.name = "#{@i}Page"
|
||||||
end
|
# end
|
||||||
if b[:content].blank?
|
# if b[:content].blank?
|
||||||
@page.content = "No Content Present"
|
# @page.content = "No Content Present"
|
||||||
else
|
# else
|
||||||
@page.content = b[:content]
|
# @page.content = b[:content]
|
||||||
end
|
# end
|
||||||
@page.save!
|
# @page.save!
|
||||||
end
|
# end
|
||||||
else
|
# else
|
||||||
puts "No Page Data"
|
# puts "No Page Data"
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
|
|
||||||
def get_variables_for_new
|
# def get_variables_for_new
|
||||||
@designs = Design.all.entries
|
# @designs = Design.all.entries
|
||||||
@themes = Design.first.themes
|
# @themes = Design.first.themes
|
||||||
@module_apps = ModuleApp.for_frontend_select
|
# @module_apps = ModuleApp.for_frontend_select
|
||||||
@app_frontend_urls = nil
|
# @app_frontend_urls = nil
|
||||||
@categories = nil
|
# @categories = nil
|
||||||
@tags = nil
|
# @tags = nil
|
||||||
@page_frontend_data_counts = nil
|
# @page_frontend_data_counts = nil
|
||||||
@frontend_styles = nil
|
# @frontend_styles = nil
|
||||||
@selected={
|
# @selected={
|
||||||
:design => @designs.first,
|
# :design => @designs.first,
|
||||||
:theme=> @themes.first,
|
# :theme=> @themes.first,
|
||||||
:module_app=>nil,#@module_apps.first
|
# :module_app=>nil,#@module_apps.first
|
||||||
:app_frontend_url=> nil, #@module_apps.first
|
# :app_frontend_url=> nil, #@module_apps.first
|
||||||
:category=>nil,
|
# :category=>nil,
|
||||||
:tag=>nil,
|
# :tag=>nil,
|
||||||
:page_frontend_data_count=>nil,
|
# :page_frontend_data_count=>nil,
|
||||||
:frontend_style => nil
|
# :frontend_style => nil
|
||||||
}
|
# }
|
||||||
end
|
# end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
+3
-1
@@ -218,7 +218,9 @@ Orbit::Application.routes.draw do
|
|||||||
get "import_data/sync_book_data"
|
get "import_data/sync_book_data"
|
||||||
get "import_data/sync_journal_paper_data"
|
get "import_data/sync_journal_paper_data"
|
||||||
get "import_data/sync_conference_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"
|
||||||
|
|
||||||
resources :tags do
|
resources :tags do
|
||||||
collection do
|
collection do
|
||||||
|
|||||||
@@ -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_auto
|
||||||
|
puts "Book Data Synchronization Complete"
|
||||||
|
p Admin::ImportDataController.new.sync_journal_paper_data_auto
|
||||||
|
puts "Journal Paper Data Synchronization Complete"
|
||||||
|
p Admin::ImportDataController.new.sync_conference_data_auto
|
||||||
|
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 << "#{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 << "(#{self.conference_paper_types.collect{|x| x.title}.join(', ')})"
|
||||||
title.join(', ')
|
title.join(', ')
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|||||||
Reference in new issue
Block a user