Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script: Convert tax tags in 'synonym of' history items to prott tags #1183

Closed
jonkerz opened this issue Nov 12, 2020 · 6 comments
Closed

Script: Convert tax tags in 'synonym of' history items to prott tags #1183

jonkerz opened this issue Nov 12, 2020 · 6 comments
Labels

Comments

@jonkerz
Copy link
Member

jonkerz commented Nov 12, 2020

TODO:

  • Write script
  • Run script

These:

@jonkerz
Copy link
Member Author

jonkerz commented Nov 12, 2020

@jonkerz jonkerz added the script label Nov 12, 2020
@jonkerz
Copy link
Member Author

jonkerz commented Nov 13, 2020

Batch 1

BATCH = 1
EDIT_SUMMARY = "Convert tax tags in 'synonym of' history items to prott tags [batch #{BATCH}] (junior synonym of), see %github1183"
ANTCATBOT = User.find_by!(name: 'AntCatBot')

# For activities and PaperTrail.
RequestStore.store[:current_request_uuid] = SecureRandom.uuid
PaperTrail.request.whodunnit = ANTCATBOT.id

def replace_with_prott_tag history_item
  puts "ID: #{history_item.id}"
  old_taxt = history_item.taxt.dup

  extracted_taxon = Taxon.find(history_item.ids_from_tax_or_taxac_tags.first)
  new_taxt = old_taxt.sub(
    /\{tax #{extracted_taxon.id}\}/,
    "{prott #{extracted_taxon.protonym.id}}"
  )

  puts "old_taxt: #{old_taxt}".yellow
  puts "new_taxt: #{new_taxt}".green
  puts

  history_item.update!(taxt: new_taxt)
  history_item.create_activity :update, ANTCATBOT, edit_summary: EDIT_SUMMARY
end

items = HistoryItem.where('taxt REGEXP ?', "^Junior synonym of {tax [0-9]+}: {ref [0-9]+}: [0-9]+\.?$"); nil

items.each do |item|
  replace_with_prott_tag item
end; nil

Activity.execute_script_activity User.find_by!(name: 'Fredrik Palmkron'), EDIT_SUMMARY

@jonkerz
Copy link
Member Author

jonkerz commented Nov 13, 2020

Batch 2

BATCH = 2
EDIT_SUMMARY = "Convert tax tags in 'synonym of' history items to prott tags [batch #{BATCH}] (senior synonym of), see %github1183"
ANTCATBOT = User.find_by!(name: 'AntCatBot')

# For activities and PaperTrail.
RequestStore.store[:current_request_uuid] = SecureRandom.uuid
PaperTrail.request.whodunnit = ANTCATBOT.id

def replace_with_prott_tag history_item
  puts "ID: #{history_item.id}"
  old_taxt = history_item.taxt.dup

  extracted_taxon = Taxon.find(history_item.ids_from_tax_or_taxac_tags.first)
  new_taxt = old_taxt.sub(
    /\{tax #{extracted_taxon.id}\}/,
    "{prott #{extracted_taxon.protonym.id}}"
  )

  puts "old_taxt: #{old_taxt}".yellow
  puts "new_taxt: #{new_taxt}".green
  puts

  history_item.update!(taxt: new_taxt)
  history_item.create_activity :update, ANTCATBOT, edit_summary: EDIT_SUMMARY
end

items = HistoryItem.where('taxt REGEXP ?', "^Senior synonym of {tax [0-9]+}: {ref [0-9]+}: [0-9]+\.?$"); nil

items.each do |item|
  replace_with_prott_tag item
end; nil

Activity.execute_script_activity User.find_by!(name: 'Fredrik Palmkron'), EDIT_SUMMARY

@jonkerz jonkerz closed this as completed Nov 14, 2020
@jonkerz
Copy link
Member Author

jonkerz commented Dec 24, 2020

Batch 3

BATCH = 3
EDIT_SUMMARY = "Convert tax tags in 'synonym of' history items to prott tags [batch #{BATCH}] (junior synonym of), see %github1183"
ANTCATBOT = User.find_by!(name: 'AntCatBot')

# For activities and PaperTrail.
RequestStore.store[:current_request_uuid] = SecureRandom.uuid
PaperTrail.request.whodunnit = ANTCATBOT.id

def replace_with_prott_tag history_item
  puts "ID: #{history_item.id}"
  old_taxt = history_item.taxt.dup

  extracted_taxon = Taxon.find(history_item.ids_from_taxon_tags.first)
  new_taxt = old_taxt.sub(
    /\{tax #{extracted_taxon.id}\}/,
    "{prott #{extracted_taxon.protonym.id}}"
  )

  puts "old_taxt: #{old_taxt}".yellow
  puts "new_taxt: #{new_taxt}".green
  puts

  history_item.update!(taxt: new_taxt)
  history_item.create_activity :update, ANTCATBOT, edit_summary: EDIT_SUMMARY
end

items = HistoryItem.where('taxt REGEXP ?', "^Junior synonym of {tax [0-9]+}: {ref [0-9]+}: "); nil

items.each do |item|
  replace_with_prott_tag item
end; nil

Activity.execute_script_activity User.find_by!(name: 'Fredrik Palmkron'), EDIT_SUMMARY

@jonkerz
Copy link
Member Author

jonkerz commented Dec 24, 2020

Batch 4

BATCH = 4
EDIT_SUMMARY = "Convert tax tags in 'synonym of' history items to prott tags [batch #{BATCH}] (senior synonym of), see %github1183"
ANTCATBOT = User.find_by!(name: 'AntCatBot')

# For activities and PaperTrail.
RequestStore.store[:current_request_uuid] = SecureRandom.uuid
PaperTrail.request.whodunnit = ANTCATBOT.id

def replace_with_prott_tag history_item
  puts "ID: #{history_item.id}"
  old_taxt = history_item.taxt.dup

  extracted_taxon = Taxon.find(history_item.ids_from_taxon_tags.first)
  new_taxt = old_taxt.sub(
    /\{tax #{extracted_taxon.id}\}/,
    "{prott #{extracted_taxon.protonym.id}}"
  )

  puts "old_taxt: #{old_taxt}".yellow
  puts "new_taxt: #{new_taxt}".green
  puts

  history_item.update!(taxt: new_taxt)
  history_item.create_activity :update, ANTCATBOT, edit_summary: EDIT_SUMMARY
end

items = HistoryItem.where('taxt REGEXP ?', "^Senior synonym of {tax [0-9]+}: {ref [0-9]+}: "); nil

items.each do |item|
  replace_with_prott_tag item
end; nil

Activity.execute_script_activity User.find_by!(name: 'Fredrik Palmkron'), EDIT_SUMMARY

@jonkerz
Copy link
Member Author

jonkerz commented Dec 24, 2020

  • Run script
Batch 5

BATCH = 5
EDIT_SUMMARY = "Convert tax tags in 'synonym of' history items to prottac tags [batch #{BATCH}] (junior synonym of), see %github1183"
ANTCATBOT = User.find_by!(name: 'AntCatBot')

# For activities and PaperTrail.
RequestStore.store[:current_request_uuid] = SecureRandom.uuid
PaperTrail.request.whodunnit = ANTCATBOT.id

def replace_with_prott_tag history_item
  puts "ID: #{history_item.id}"
  old_taxt = history_item.taxt.dup

  extracted_taxon = Taxon.find(history_item.ids_from_taxon_tags.first)
  new_taxt = old_taxt.sub(
    /\{taxac #{extracted_taxon.id}\}/,
    "{prottac #{extracted_taxon.protonym.id}}"
  )

  puts "old_taxt: #{old_taxt}".yellow
  puts "new_taxt: #{new_taxt}".green
  puts

  history_item.update!(taxt: new_taxt)
  history_item.create_activity :update, ANTCATBOT, edit_summary: EDIT_SUMMARY
end

items = HistoryItem.where('taxt REGEXP ?', "^Junior synonym of {taxac [0-9]+}: {ref [0-9]+}: "); nil

items.each do |item|
  replace_with_prott_tag item
end; nil

Activity.execute_script_activity User.find_by!(name: 'Fredrik Palmkron'), EDIT_SUMMARY

  • Run script
Batch 6

BATCH = 6
EDIT_SUMMARY = "Convert tax tags in 'synonym of' history items to prottac tags [batch #{BATCH}] (senior synonym of), see %github1183"
ANTCATBOT = User.find_by!(name: 'AntCatBot')

# For activities and PaperTrail.
RequestStore.store[:current_request_uuid] = SecureRandom.uuid
PaperTrail.request.whodunnit = ANTCATBOT.id

def replace_with_prott_tag history_item
  puts "ID: #{history_item.id}"
  old_taxt = history_item.taxt.dup

  extracted_taxon = Taxon.find(history_item.ids_from_taxon_tags.first)
  new_taxt = old_taxt.sub(
    /\{taxac #{extracted_taxon.id}\}/,
    "{prottac #{extracted_taxon.protonym.id}}"
  )

  puts "old_taxt: #{old_taxt}".yellow
  puts "new_taxt: #{new_taxt}".green
  puts

  history_item.update!(taxt: new_taxt)
  history_item.create_activity :update, ANTCATBOT, edit_summary: EDIT_SUMMARY
end

items = HistoryItem.where('taxt REGEXP ?', "^Senior synonym of {taxac [0-9]+}: {ref [0-9]+}: "); nil

items.each do |item|
  replace_with_prott_tag item
end; nil

Activity.execute_script_activity User.find_by!(name: 'Fredrik Palmkron'), EDIT_SUMMARY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant