Compare commits
1 Commits
master
...
ntu_mb_dat
Author | SHA1 | Date |
---|---|---|
Matt K. Fu | 9162c4306c |
|
@ -0,0 +1,6 @@
|
||||||
|
[{"old_id":1,"key":"administrative","title_translations":{"en":"Official","zh_tw":"行政公告"}}
|
||||||
|
,{"old_id":2,"key":"events","title_translations":{"en":"Activities","zh_tw":"活動"}}
|
||||||
|
,{"old_id":3,"key":"intern_opportunities","title_translations":{"en":"Internship","zh_tw":"實習機會"}}
|
||||||
|
,{"old_id":4,"key":"scholarship_and_exchange_student","title_translations":{"en":"Scholarship","zh_tw":"獎學金與交換生資訊"}}
|
||||||
|
,{"old_id":5,"key":"news","title_translations":{"en":"Newsletter","zh_tw":"新聞"}}
|
||||||
|
,{"old_id":6,"key":"enrollments","title_translations":{"en":"Admission","zh_tw":"招生資訊"}}]
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,55 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
require 'pry'
|
||||||
|
namespace :import do
|
||||||
|
task :ntu_mb_news_report => :environment do
|
||||||
|
|
||||||
|
jfile = File.new("#{Rails.root}/lib/import_data/news_report.json").read
|
||||||
|
jdata = JSON.parse(jfile)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
task :ntu_mb => :environment do
|
||||||
|
DEPARTMENTS = %w[Management BA Acc Fin IB IM EMBA GMBA]
|
||||||
|
print 'Enter the numer of department you want to import'
|
||||||
|
puts DEPARTMENTS.map.with_index{|t,i| "#{i}.#{t}" }.to_s
|
||||||
|
num = STDIN.gets.gsub("\n",'').to_i
|
||||||
|
|
||||||
|
puts "Destroy all BulletinCategory? (Default No)"
|
||||||
|
if STDIN.gets.gsub("\n",'').downcase == 'yes'
|
||||||
|
BulletinCategory.destroy_all
|
||||||
|
else
|
||||||
|
puts "Did not destroy"
|
||||||
|
end
|
||||||
|
jfile = File.new("#{Rails.root}/lib/import_data/announce_categories.json").read
|
||||||
|
jdata = JSON.parse(jfile)
|
||||||
|
jdata.each do |data|
|
||||||
|
a = BulletinCategory.new data
|
||||||
|
a.save
|
||||||
|
end
|
||||||
|
news_report_category = BulletinCategory.new {"key":"news_report","title_translations":{"en":"NewsReport","zh_tw":"新聞報導"}}
|
||||||
|
puts "Imported #{jdata.count}+1(NewsReport)"
|
||||||
|
|
||||||
|
|
||||||
|
puts "Destroy all Bulletin? (Default No)"
|
||||||
|
if STDIN.gets.gsub("\n",'').downcase == 'yes'
|
||||||
|
Bulletin.destroy_all
|
||||||
|
else
|
||||||
|
puts "Did not destroy"
|
||||||
|
end
|
||||||
|
counter = 0
|
||||||
|
jfile = File.new("#{Rails.root}/lib/import_data/announcements.json").read
|
||||||
|
jdata = JSON.parse(jfile)
|
||||||
|
jdata.each do |data|
|
||||||
|
# puts data
|
||||||
|
# puts DEPARTMENTS[num]
|
||||||
|
if data["department"] == DEPARTMENTS[num]
|
||||||
|
a = Bulletin.new data
|
||||||
|
a.bulletin_category = BulletinCategory.where(:key=>data["category_key"]).first
|
||||||
|
a.save
|
||||||
|
counter = counter +1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
puts "Imported #{counter}"
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue