Sha256: 3ec102d1bddd359321a325aee9a0903ab6e6c9301a16da5cb8ceae366a4053c6

Contents?: true

Size: 917 Bytes

Versions: 3

Compression:

Stored size: 917 Bytes

Contents

#! /usr/bin/env ruby
require 'cablegator'
require 'cablegator/wikileaks'

dir_prefix = ARGV[0] || Dir.pwd

puts "Downloading cables to #{File.expand_path(dir_prefix)}"
doc = Nokogiri::HTML(WikiLeaks.home)

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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cablegator-0.9.2 bin/download_cables
cablegator-0.9.1 bin/download_cables
cablegator-0.9.0 bin/download_cables