Created
June 22, 2014 12:24
-
-
Save dtinth/ec533420050822ae82d3 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
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