bin/download_cables in cablegator-0.9.2 vs bin/download_cables in cablegator-0.9.9
- old
+ new
@@ -1,25 +1,19 @@
#! /usr/bin/env ruby
require 'cablegator'
-require 'cablegator/wikileaks'
+require 'fileutils'
dir_prefix = ARGV[0] || Dir.pwd
puts "Downloading cables to #{File.expand_path(dir_prefix)}"
-doc = Nokogiri::HTML(WikiLeaks.home)
+Wikileaks.with_each_cable do |cable_url|
+ file_location = File.expand_path(dir_prefix + cable_url)
+ reference_id = Wikileaks.reference_id(cable_url)
-doc.css(%{a[href^='/date']}).each do |link|
- page_with_cables = Nokogiri::HTML(WikiLeaks.get(link.attributes['href'].value))
- page_with_cables.css(%{a[href^='/cable']}).each do |cable|
- cable_url = cable.attributes['href'].value
- file_location = File.expand_path(dir_prefix + cable_url)
- reference_id = File.basename(cable_url).gsub(File.extname(cable_url),'')
-
- if !File.exist?(file_location)
- FileUtils.mkdir_p(File.dirname(file_location))
- STDOUT.puts "Downloading cable #{reference_id} to #{file_location}"
- File.open(file_location, 'w') { |f| f << WikiLeaks.get(cable_url) }
- else
- STDOUT.puts "You already have #{reference_id} in #{file_location}"
- end
+ if !File.exist?(file_location)
+ FileUtils.mkdir_p(File.dirname(file_location))
+ STDOUT.puts "Downloading cable #{reference_id} to #{file_location}"
+ File.open(file_location, 'w') { |f| f << WikiLeaks.get(cable_url) }
+ else
+ STDOUT.puts "You already have #{reference_id} in #{file_location}"
end
end