2017-05-18 12:12:35 +00:00
|
|
|
namespace :hps_task do
|
|
|
|
task :import => :environment do
|
|
|
|
file = File.join(Rails.root, "public", "hps", "cities.json")
|
|
|
|
data = File.read(file)
|
|
|
|
cities = JSON.parse(data)
|
|
|
|
cities.each do |city|
|
|
|
|
hpscity = HpsCity.where(:old_id => city["old_id"]).first rescue nil
|
|
|
|
if hpscity.nil?
|
|
|
|
hpscity = HpsCity.new
|
|
|
|
end
|
|
|
|
hpscity.old_id = city["old_id"]
|
|
|
|
hpscity.name = city["name"]
|
|
|
|
hpscity.save
|
|
|
|
end
|
|
|
|
file = File.join(Rails.root, "public", "hps", "counties.json")
|
|
|
|
data = File.read(file)
|
|
|
|
counties = JSON.parse(data)
|
|
|
|
counties.each do |county|
|
|
|
|
hpscounty = HpsCounty.where(:old_id => county["old_id"]).first rescue nil
|
|
|
|
if hpscounty.nil?
|
|
|
|
hpscounty = HpsCounty.new
|
|
|
|
end
|
|
|
|
hpscounty.old_id = county["old_id"]
|
|
|
|
hpscounty.name = county["name"]
|
|
|
|
hpscounty.zip_code = county["zip_code"]
|
|
|
|
city = HpsCity.where(:old_id => county["cityID"]).first
|
|
|
|
hpscounty.hps_city = city
|
|
|
|
hpscounty.save
|
|
|
|
end
|
|
|
|
file = File.join(Rails.root, "public", "hps", "schools.json")
|
|
|
|
data = File.read(file)
|
|
|
|
schools = JSON.parse(data)
|
|
|
|
schools.each do |school|
|
|
|
|
hpsschool = HpsSchool.where(:old_id => school["old_id"]).first rescue nil
|
|
|
|
if hpsschool.nil?
|
|
|
|
hpsschool = HpsSchool.new
|
|
|
|
end
|
|
|
|
hpsschool.old_id = school["old_id"]
|
|
|
|
hpsschool.name = school["name"]
|
|
|
|
hpsschool.address = school["address"]
|
|
|
|
hpsschool.telephone = school["telephone"]
|
|
|
|
hpsschool.land = school["land"]
|
|
|
|
hpsschool.url = school["url"]
|
|
|
|
hpsschool.type = school["type"]
|
|
|
|
city = HpsCity.where(:old_id => school["City"]).first
|
|
|
|
county = HpsCounty.where(:old_id => school["CityZip"]).first
|
|
|
|
hpsschool.hps_city = city
|
|
|
|
hpsschool.hps_county = county
|
|
|
|
hpsschool.save
|
|
|
|
end
|
|
|
|
end
|
2017-05-24 08:57:46 +00:00
|
|
|
|
|
|
|
task :import_school_users => :environment do
|
|
|
|
file = File.join(Rails.root, "public", "hps", "school_user.json")
|
|
|
|
data = File.read(file)
|
|
|
|
users = JSON.parse(data)
|
|
|
|
users.each do |user|
|
|
|
|
hpsm = HpsMember.where(:old_id => user["old_id"]).first rescue nil
|
2017-05-24 09:12:33 +00:00
|
|
|
if hpsm.nil?
|
2017-05-24 08:57:46 +00:00
|
|
|
hpsm = HpsMember.new
|
|
|
|
end
|
2017-05-24 09:12:33 +00:00
|
|
|
puts "Createing acccount #{user["account"]}"
|
2017-05-24 08:57:46 +00:00
|
|
|
hpsm.old_id = user["old_id"]
|
|
|
|
hpsm.account = user["account"]
|
|
|
|
hpsm.password = user["password"]
|
|
|
|
hpsm.name = user["name"]
|
|
|
|
hpsm.telephone = user["telephone"]
|
|
|
|
hpsm.mobile = user["mobile"]
|
|
|
|
hpsm.email = user["email"]
|
|
|
|
hpsm.address = user["address"]
|
|
|
|
hpsm.title = user["title"]
|
|
|
|
school = HpsSchool.where(:old_id => user["SchoolID"]).first
|
2017-05-24 09:12:33 +00:00
|
|
|
hpsm.hps_school_id = school.id.to_s if !school.nil?
|
2017-05-24 08:57:46 +00:00
|
|
|
city = HpsCity.where(:old_id => user["my_county"]).first
|
2017-05-24 09:12:33 +00:00
|
|
|
hpsm.hps_city_id = city.id.to_s if !city.nil?
|
2017-05-24 08:57:46 +00:00
|
|
|
county = HpsCounty.where(:old_id => user["cityzip"]).first
|
2017-05-24 09:12:33 +00:00
|
|
|
hpsm.hps_county_id = county.id.to_s if !county.nil?
|
2017-05-24 08:57:46 +00:00
|
|
|
hpsm.save
|
|
|
|
end
|
|
|
|
end
|
2017-05-18 12:12:35 +00:00
|
|
|
end
|