Skip to content

Instantly share code, notes, and snippets.

@zspencer
Created July 14, 2012 20:25
Show Gist options
  • Save zspencer/3113204 to your computer and use it in GitHub Desktop.
Save zspencer/3113204 to your computer and use it in GitHub Desktop.
The shitty script I threw together to keep my DAS updated.
credentials.rb
chromedriver.log
.rvmrc
Gemfile.lock
require 'capybara'
require 'capybara/dsl'
require 'selenium-webdriver'
require_relative 'credentials'
DOWNLOAD_DIR=File.expand_path('~/Movies/DAS')
INCLUDE_IOS = false
Capybara.default_driver = :chrome
Capybara.app_host = 'https://www.destroyallsoftware.com'
Capybara.register_driver :chrome do |app|
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 600
profile = Selenium::WebDriver::Chrome::Profile.new
profile['download.prompt_for_download'] = false
profile['download.default_directory'] = DOWNLOAD_DIR
Capybara::Selenium::Driver.new(app, { browser: :chrome, http_client: client, profile: profile })
end
Capybara.default_wait_time = 600
include Capybara::DSL
files = Dir.entries(DOWNLOAD_DIR).select do |f|
f.include?('das')
end.map do |f|
f.gsub('.mov','').split('-').slice(2..-1).join('-')
end
def not_downloaded?(href, files)
!files.any? { |f| href.include? f }
end
visit "/screencasts/users/sign_in"
fill_in "Email", with: DAS_USERNAME
fill_in "Password", with: DAS_PASSWORD
click_button "Sign in"
all('a', text: "Download").each do |link|
next if(!INCLUDE_IOS and link[:href].include?('ios'))
if(not_downloaded?(link[:href], files))
p "downloading #{link[:href]}"
link.click
end
end
wait_until { Dir.entries(DOWNLOAD_DIR).none? { |f| f.include?('crdownload') } }
source :rubygems
gem 'capybara'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment