Skip to content

Instantly share code, notes, and snippets.

@flsafe

flsafe/gist:1317532

Created Oct 26, 2011
Embed
What would you like to do?
LAWN_CARE_SIC = "0782"
def get_sic_code(sic)
SicCode.first(sic_code:sic)
end
def fix_lawn_care_sic
sic_code = get_sic_code(LAWN_CARE_SIC)
sic_code.category = GCS::Category.first_by_title('lawn-and-garden')
sic_code.sub_category = GCS::SubCategory.first_by_title('lawn-care')
sic_code.save
end
def re_cat_businesses
failed = []
success = 0
movie_dist = GCS::SubCategory.first_by_title('movie-distribution')
movie_dist.businesses.each do |b|
b.sic_code = '0' + b.sic_code if b.sic_code.count == 5
b.update_category
if b.save
success += 1
else
failed << b
end
end
{failed:failed, success:success}
end
def print_failures(failed)
puts "Failed to save #{failed.count}"
File.open('failed.txt', 'w') do |f|
failed.each do |b|
f.puts "Failed to save #{b.name}"
b.errors.each{|e| f.puts e}
end
end
end
if fix_lawn_care_sic()
result = re_cat_businesses()
if result[:failed].empty?
puts "OK, all businesses updated"
else
puts "#{result[:success]} businesses updated"
print_failures(result[:failed])
end
else
puts "Sic code update failed"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.