Created
October 26, 2011 19:33
-
-
Save flsafe/1317532 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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