cablegator 0.9.2 → 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ .rvmrc
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
1
  source 'http://gemcutter.org'
2
2
  gem 'nokogiri'
3
3
  gem 'httparty'
4
+ gem 'twitter'
5
+ gem 'oauth'
6
+ gem 'launchy'
data/Gemfile.lock CHANGED
@@ -1,14 +1,43 @@
1
1
  GEM
2
2
  remote: http://gemcutter.org/
3
3
  specs:
4
+ addressable (2.2.2)
5
+ configuration (1.2.0)
4
6
  crack (0.1.8)
7
+ faraday (0.5.3)
8
+ addressable (~> 2.2.2)
9
+ multipart-post (~> 1.0.1)
10
+ rack (>= 1.1.0, < 2)
11
+ faraday_middleware (0.3.1)
12
+ faraday (~> 0.5.3)
13
+ hashie (0.4.0)
5
14
  httparty (0.6.1)
6
15
  crack (= 0.1.8)
16
+ launchy (0.3.7)
17
+ configuration (>= 0.0.5)
18
+ rake (>= 0.8.1)
19
+ multi_json (0.0.5)
20
+ multi_xml (0.2.0)
21
+ multipart-post (1.0.1)
7
22
  nokogiri (1.4.4)
23
+ oauth (0.4.4)
24
+ rack (1.2.1)
25
+ rake (0.8.7)
26
+ simple_oauth (0.1.3)
27
+ twitter (1.0.0)
28
+ faraday (~> 0.5.3)
29
+ faraday_middleware (~> 0.3.0)
30
+ hashie (~> 0.4.0)
31
+ multi_json (~> 0.0.5)
32
+ multi_xml (~> 0.2.0)
33
+ simple_oauth (~> 0.1.2)
8
34
 
9
35
  PLATFORMS
10
36
  ruby
11
37
 
12
38
  DEPENDENCIES
13
39
  httparty
40
+ launchy
14
41
  nokogiri
42
+ oauth
43
+ twitter
data/README.md CHANGED
@@ -1,20 +1,28 @@
1
1
  # cablegator
2
2
  Downloads WikiLeaks CableGate cables for offline viewing and archiving
3
+ Tweets link to Wikileaks CableGate cables- making the information within easy reach of the twitterverse.
3
4
 
4
5
  Install via:
5
6
  <code>
6
7
  > gem install cablegator
7
8
  </code>
8
9
 
9
-
10
10
  Run Via:
11
11
  <code>
12
- $ download_cables ..
13
- Downloading cables to /Users/csquared/projects/cablegator
14
- You already have 66BUENOSAIRES2481 in /Users/csquared/projects/cablegator/cable/1966/12/66BUENOSAIRES2481.html
15
- You already have 72TEHRAN1164 in /Users/csquared/projects/cablegator/cable/1972/02/72TEHRAN1164.html
16
- You already have 72TEHRAN5055 in /Users/csquared/projects/cablegator/cable/1972/08/72TEHRAN5055.htm
17
- Downloading cable 75TEHRAN2069 to /Users/csquared/projects/cablegator//cable/1975/03/75TEHRAN2069.html
18
- ...
12
+ > download_cables <path>
13
+ </code>
19
14
 
15
+ And
16
+ <code>
17
+ > tweet_cables <delay in seconds>
20
18
  </code>
19
+ You will then be prompted to login to Twitter from the cmd line.
20
+ From here the program tweets links to all the cables, waiting between posts. Default delay is 1 second.
21
+
22
+ #TODO:
23
+ * DONE - Don't tweet if already tweeted
24
+ * Allow tweet customization
25
+ * Create webapp to run this
26
+
27
+ #Features:
28
+ * Disqualifies you from employment at various federal agencies.
data/TODO ADDED
@@ -0,0 +1,5 @@
1
+
2
+ * tweet the rest of the cables
3
+ -- search for if tag has been already posted
4
+ -- otherwise figure out some way to resume posting
5
+ * tweet the subjects with references to the hashtag
data/bin/download_cables CHANGED
@@ -1,25 +1,19 @@
1
1
  #! /usr/bin/env ruby
2
2
  require 'cablegator'
3
- require 'cablegator/wikileaks'
3
+ require 'fileutils'
4
4
 
5
5
  dir_prefix = ARGV[0] || Dir.pwd
6
6
 
7
7
  puts "Downloading cables to #{File.expand_path(dir_prefix)}"
8
- doc = Nokogiri::HTML(WikiLeaks.home)
8
+ Wikileaks.with_each_cable do |cable_url|
9
+ file_location = File.expand_path(dir_prefix + cable_url)
10
+ reference_id = Wikileaks.reference_id(cable_url)
9
11
 
10
- doc.css(%{a[href^='/date']}).each do |link|
11
- page_with_cables = Nokogiri::HTML(WikiLeaks.get(link.attributes['href'].value))
12
- page_with_cables.css(%{a[href^='/cable']}).each do |cable|
13
- cable_url = cable.attributes['href'].value
14
- file_location = File.expand_path(dir_prefix + cable_url)
15
- reference_id = File.basename(cable_url).gsub(File.extname(cable_url),'')
16
-
17
- if !File.exist?(file_location)
18
- FileUtils.mkdir_p(File.dirname(file_location))
19
- STDOUT.puts "Downloading cable #{reference_id} to #{file_location}"
20
- File.open(file_location, 'w') { |f| f << WikiLeaks.get(cable_url) }
21
- else
22
- STDOUT.puts "You already have #{reference_id} in #{file_location}"
23
- end
12
+ if !File.exist?(file_location)
13
+ FileUtils.mkdir_p(File.dirname(file_location))
14
+ STDOUT.puts "Downloading cable #{reference_id} to #{file_location}"
15
+ File.open(file_location, 'w') { |f| f << WikiLeaks.get(cable_url) }
16
+ else
17
+ STDOUT.puts "You already have #{reference_id} in #{file_location}"
24
18
  end
25
19
  end
data/bin/tweet_cables ADDED
@@ -0,0 +1,26 @@
1
+ #! /usr/bin/env ruby
2
+ require 'twitter'
3
+ require 'cablegator'
4
+ require 'cablegator/twitter'
5
+
6
+ Twitter.command_line_login
7
+ tweeted = CableGator.save_file("~/.cablegator/tweeted")
8
+
9
+ puts "Tweeting cables"
10
+ WikiLeaks.with_each_cable do |cable_url|
11
+ reference_id = WikiLeaks.reference_id(cable_url)
12
+ if tweeted.include?(reference_id)
13
+ puts "Already tweeted #{reference_id}"
14
+ else
15
+ tweet = "#cablegate ##{reference_id} #{WikiLeaks.base_uri + cable_url}"
16
+ puts "Tweeting: #{tweet}"
17
+ begin
18
+ Twitter.update(tweet)
19
+ tweeted << reference_id
20
+ delay = ARGV[0].to_i rescue nil
21
+ sleep(delay || 1)
22
+ rescue
23
+ "Tweet #{reference_id} failed"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ #! /usr/bin/env ruby
2
+ require 'twitter'
3
+ require 'cablegator'
4
+ require 'cablegator/twitter'
5
+
6
+ Twitter.command_line_login
7
+ tweeted = CableGator.save_file("~/.cablegator/tweeted_fmt_#{ARGV[0].to_s.gsub(/:| /,'')}")
8
+
9
+ puts "Tweeting cables"
10
+ WikiLeaks.with_each_cable_data do |cable_data|
11
+ reference_id = cable_data['reference_id']
12
+
13
+ if tweeted.include?(reference_id)
14
+ puts "Already tweeted #{reference_id}"
15
+ else
16
+ format_string = ARGV[0].to_s.dup
17
+ cable_data.each { |k,v| format_string.gsub!(/\:#{k}/,v) }
18
+
19
+ tweet = "#cablegate ##{reference_id} #{format_string}"
20
+
21
+ puts "Tweeting: #{tweet}"
22
+ begin
23
+ Twitter.update(tweet)
24
+ tweeted << reference_id
25
+ delay = ARGV[1].to_i rescue nil
26
+ sleep(delay || 10)
27
+ rescue
28
+ "Tweet #{reference_id} failed"
29
+ end
30
+ end
31
+ end
data/cablegator.gemspec CHANGED
@@ -16,6 +16,9 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_dependency('nokogiri')
18
18
  s.add_dependency('httparty')
19
+ s.add_dependency('twitter')
20
+ s.add_dependency('oauth')
21
+ s.add_dependency('launchy')
19
22
 
20
23
  s.files = `git ls-files`.split("\n")
21
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/lib/cablegator.rb CHANGED
@@ -1,12 +1,22 @@
1
1
  # library loader
2
- require 'rubygems'
3
- #require 'bundler'
4
- #Bundler.setup
2
+ # require 'rubygems'
3
+ # require 'bundler'
4
+ # Bundler.setup
5
5
 
6
6
  $LOAD_PATH.unshift(File.dirname(__FILE__)) unless $LOAD_PATH.include?(File.dirname(__FILE__))
7
7
 
8
- # gems
9
- require 'open-uri'
10
- require 'nokogiri'
11
- require 'httparty'
12
- require 'fileutils'
8
+ require 'cablegator/wikileaks'
9
+
10
+ module CableGator
11
+ def self.save_file(pathname)
12
+ require 'fileutils'
13
+ save_file = File.expand_path(pathname)
14
+ FileUtils.mkdir_p(File.dirname(save_file))
15
+
16
+ tweeted = File.read(save_file).split(',') rescue []
17
+ at_exit do
18
+ File.open(save_file, 'w') { |f| f << tweeted.join(',') }
19
+ end
20
+ tweeted
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ require 'oauth'
2
+ require 'launchy'
3
+
4
+ module Twitter
5
+ def self.command_line_login
6
+ consumer_key = 'ddxhhHSHys7210VR8lhYag'
7
+ consumer_secret = 'FN5kIDAvwWU4jb54JMfWWTbtpI30JKeEmRWMYSMYk'
8
+
9
+ oauth_client = OAuth::Consumer.new(consumer_key, consumer_secret,
10
+ :site => 'http://api.twitter.com',
11
+ :request_endpoint => 'http://api.twitter.com',
12
+ :sign_in => true)
13
+
14
+ req_token = oauth_client.get_request_token
15
+ Launchy.open(req_token.authorize_url)
16
+
17
+ puts "\nAllow access to get pin\n"
18
+
19
+ puts "Enter Pin: "
20
+ pin = STDIN.gets.strip
21
+
22
+ begin
23
+ access_token = req_token.get_access_token(:oauth_verifier => pin)
24
+
25
+ Twitter.configure do |config|
26
+ config.consumer_key = access_token.consumer.key
27
+ config.consumer_secret = access_token.consumer.secret
28
+ config.oauth_token = access_token.token
29
+ config.oauth_token_secret = access_token.secret
30
+ end
31
+ rescue
32
+ STDOUT.puts "Twitter Authentication failed - please try again"
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module Cablegator
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.9"
3
3
  end
@@ -1,12 +1,66 @@
1
+ require 'socket'
2
+ require 'timeout'
3
+ require 'nokogiri'
4
+ require 'httparty'
5
+
1
6
  class WikiLeaks
2
7
  include HTTParty
8
+ PROXY_URL = 'localhost'
9
+ PROXY_PORT = 8118
3
10
  base_uri 'http://wikileaks.ch'
4
11
 
12
+ #let's check for tor on privoxy
13
+ Timeout::timeout(1) do
14
+ TCPSocket.new(PROXY_URL, PROXY_PORT).close
15
+ http_proxy 'localhost', 8118
16
+ puts "Using TOR!"
17
+ end rescue nil
18
+
5
19
  HOME = '/cablegate.html'
6
20
 
7
21
  class << self
8
- def home
9
- self.get(HOME)
22
+ def reference_id(cable_url)
23
+ File.basename(cable_url).gsub(File.extname(cable_url),'')
24
+ end
25
+
26
+ def with_each_cable
27
+ doc = Nokogiri::HTML(self.get(HOME))
28
+ doc.css(%{a[href^='/date']}).each do |link|
29
+ cable_url = link.attributes['href'].value
30
+ begin
31
+ page_with_cables = Nokogiri::HTML(WikiLeaks.get(cable_url))
32
+ page_with_cables.css(%{a[href^='/cable']}).each do |cable|
33
+ cable_url = cable.attributes['href'].value
34
+ yield cable_url
35
+ end
36
+ rescue
37
+ STDOUT.puts "error GETtin page #{cable_url}"
38
+ end
39
+ end
40
+ end
41
+
42
+ def with_each_cable_data
43
+ doc = Nokogiri::HTML(self.get(HOME))
44
+ doc.css(%{a[href^='/date']}).each do |link|
45
+ cable_url = link.attributes['href'].value
46
+ begin
47
+ page_with_cables = Nokogiri::HTML(WikiLeaks.get(cable_url))
48
+ page_with_cables.css(%{table.cable tr:has(td)}).each do |cable|
49
+ cable_hash = {}
50
+ #cable_hash['cable_url'] = cable.css(%{a[href='/cable']}).first.attributes['href'].value
51
+ children = cable.element_children.map{ |x| x.text.strip }
52
+ cable_hash['reference_id'] = children[0]
53
+ cable_hash['subject'] = children[1]
54
+ cable_hash['origin_date'] = children[2]
55
+ cable_hash['release_date'] = children[3]
56
+ cable_hash['classification'] = children[4]
57
+ cable_hash['location'] = children[5]
58
+ yield cable_hash
59
+ end
60
+ rescue
61
+ STDOUT.puts "error GETtin page #{cable_url}"
62
+ end
63
+ end
10
64
  end
11
65
  end
12
66
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 2
9
- version: 0.9.2
8
+ - 9
9
+ version: 0.9.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - csquared
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-11 00:00:00 -06:00
17
+ date: 2010-12-13 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -43,11 +43,52 @@ dependencies:
43
43
  version: "0"
44
44
  type: :runtime
45
45
  version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: twitter
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :runtime
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
60
+ name: oauth
61
+ prerelease: false
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ type: :runtime
71
+ version_requirements: *id004
72
+ - !ruby/object:Gem::Dependency
73
+ name: launchy
74
+ prerelease: false
75
+ requirement: &id005 !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ type: :runtime
84
+ version_requirements: *id005
46
85
  description: Downloads Wikileaks Cables to current directory
47
86
  email:
48
87
  - christopher.continanza@gmail.com
49
88
  executables:
50
89
  - download_cables
90
+ - tweet_cables
91
+ - tweet_cables_format
51
92
  extensions: []
52
93
 
53
94
  extra_rdoc_files: []
@@ -58,9 +99,13 @@ files:
58
99
  - Gemfile.lock
59
100
  - README.md
60
101
  - Rakefile
102
+ - TODO
61
103
  - bin/download_cables
104
+ - bin/tweet_cables
105
+ - bin/tweet_cables_format
62
106
  - cablegator.gemspec
63
107
  - lib/cablegator.rb
108
+ - lib/cablegator/twitter.rb
64
109
  - lib/cablegator/version.rb
65
110
  - lib/cablegator/wikileaks.rb
66
111
  has_rdoc: true