Skip to content

Instantly share code, notes, and snippets.

@ilyakava
Created February 19, 2014 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyakava/9100474 to your computer and use it in GitHub Desktop.
Save ilyakava/9100474 to your computer and use it in GitHub Desktop.
require 'csv'
require 'ruby-progressbar'
past_results = {}
filename = '/Users/artsyinc/Downloads/OpenContentGRI_out.csv'
length = %x(wc -l #{filename}).to_i
CSV.open('../new_getty2.csv', 'w') do |w_line|
pb = ProgressBar.create(:title => 'slugify artists', :total => length)
w_line << ['FileName','ArtworkCreator','ArtworkDateCreated','ArtworkTitle','Description','Title','Type','FileSize', 'slug_guess_1', 'slug_guess_2']
CSV.foreach(filename) do |r_line|
artist = r_line[1]
# get all the words before the 2nd comma - where the name tends to be
artist = artist.split(",")[0..1].join(" ") if artist
slugs = past_results[artist] || Artist.match(artist).map { |a| a._slugs.last if a.slugs }.compact[0..1]
while slugs.length < 2 do
slugs << ""
end
past_results[artist] = slugs
w_line << (r_line + slugs)
pb.increment
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment