Skip to content

Instantly share code, notes, and snippets.

@rosy1280
Last active January 16, 2016 00:02
Show Gist options
  • Save rosy1280/5852e40840fbf19ba6c2 to your computer and use it in GitHub Desktop.
Save rosy1280/5852e40840fbf19ba6c2 to your computer and use it in GitHub Desktop.
add new tag to a list of objects
#!/usr/bin/env ruby
# script should be placed in the common-accessioning/current/bin directory
# usage is ruby addTagScript.rb {env} druid-list.txt
# where {env} is the environment in which you want to run the script (production, test, development)
# and druid-list.txt is the list of druids you want to add tags to.
# NOTE: you need to change the tag, right now its set to add 'Project : Chinese Topographic Maps'
unless(ARGV.first.nil?)
ENV['ROBOT_ENVIRONMENT'] = ARGV.first
end
require File.expand_path(File.dirname(__FILE__) + '/../config/boot')
#pull the file from the commandline argument and read each line into the druids array
druids = []
druidlist = File.open(ARGV.second)
druidlist.each_line {|line|
druids.push line.chomp
}
druids.each do |druid|
begin
#format the druids
druid = "druid:#{druid}" unless druid.start_with?('druid')
#make sure that they exist in dor
@object=Dor::Item.find(druid)
#add the new tag and save
#TO DO: add the tag via a commandline argument, not hardcoded
@object.add_tag('Project : Chinese Topographic Maps')
@object.save
puts "completed #{druid}"
# TO DO: need to rescue error messages
# rescue
# RuntimeError => msg
# puts "#{druid}, #{msg}"
end
end
puts "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment