Created
April 30, 2011 04:19
-
-
Save kakutani/949398 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'pit' | |
require 'mechanize' | |
require 'logger' | |
require 'uri' | |
require 'fileutils' | |
MY_DROPBOX_BASE="/path/to/your/dropbox/folder" | |
BASE_URL = 'https://esrv.org/jtrapja' | |
def extract_rev_of(link) | |
link.href[/-(\d+)M?/, 1].to_i | |
end | |
def fetch_latest_pdf(links, type, user, pwd) | |
candidates = links.select{|e| e.href =~ /agile-samurai-ja.+-#{type}-.*/} | |
latest = candidates.sort_by{|e| extract_rev_of(e)}.reverse.first | |
url = [BASE_URL, latest.href].join('/') | |
wget_cmd = "wget --no-check-certificate --user=#{user} --password=#{pwd} #{url}" | |
puts wget_cmd;system(wget_cmd) | |
File.basename(latest.href) | |
end | |
config = Pit.get('esrv.org', :require => { | |
'username' => 'id for esrv.org', | |
'password' => 'password for esrv.org'}) | |
clean_target = Dir.glob("./agile-samurai*screen*.pdf*") || [] | |
FileUtils.rm(clean_target, :verbose => true) if 0 < clean_target.size | |
agent = Mechanize.new | |
agent.auth((user = config['username']), (pwd = config['password'])) | |
agent.get(BASE_URL) | |
file_names = agent.page.links_with(:text => /agile-samurai/) | |
ja_latest_fname = fetch_latest_pdf(file_names, 'ja', user, pwd) | |
enja_latest_fname = fetch_latest_pdf(file_names, 'enja', user, pwd) | |
FileUtils.mv(ja_latest_fname, File.join(MY_DROPBOX_BASE, 'agile-samurai-ja-latest.pdf')) | |
FileUtils.mv(enja_latest_fname, File.join(MY_DROPBOX_BASE, 'agile-samurai-enja-latest.pdf')) | |
File.open(File.join(MY_DROPBOX_BASE, 'agile-samurai-version.txt'), 'w') do |f| | |
f.puts ja_latest_fname | |
f.puts enja_latest_fname | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment