Skip to content

Instantly share code, notes, and snippets.

@dtinth
Created June 22, 2014 12:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtinth/ec533420050822ae82d3 to your computer and use it in GitHub Desktop.
Save dtinth/ec533420050822ae82d3 to your computer and use it in GitHub Desktop.
require 'watir-webdriver'
puts "== Album Description Updater =="
description = File.read(ARGV[0])
parts = description.scan(/https:\/\/www\.facebook\.com\/.*?\/media_set\S+/)
puts "There are #{parts.length} albums whose descriptions are to be updated!"
browser = Watir::Browser.new :firefox, :profile => 'watir'
parts.each do |part|
album_url = if part =~ /a\.(\d+)\.\d+\.(\d+)/
"https://m.facebook.com/#{$2}/albums/#{$1}/"
else
raise "Cannot generate Edit Album URL"
end
browser.goto album_url
# Click the Edit link
browser.a(href: /photos\/edit\/album/).click
album_title = browser.input(name: 'title').value
puts "- Updating: #{album_title}"
# Update the description
text = description.gsub(part) { "(this album)" }
browser.textarea(name: 'description').value = text
# Click the Submit button
browser.input(type: 'submit').click
end
puts
puts "All done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment