52 lines
1.8 KiB
Ruby
52 lines
1.8 KiB
Ruby
|
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
|
||
|
end
|