ecfs 0.0.1
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 +17 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +11 -0
- data/ecfs.gemspec +26 -0
- data/lib/ecfs.rb +5 -0
- data/lib/ecfs/proceedings_query.rb +100 -0
- data/lib/ecfs/version.rb +3 -0
- data/test/helper.rb +17 -0
- data/test/test_proceedings_query.rb +53 -0
- metadata +126 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Alan deLevie
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# ECFS
|
2
|
+
|
3
|
+
ECFS helps you download and parse filings from the FCC's Electronic Comment Filing System.
|
4
|
+
|
5
|
+
[](https://travis-ci.org/adelevie/ecfs)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ecfs'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```sh
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```sh
|
24
|
+
$ gem install ecfs
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
|
31
|
+
# get info about a specific proceeding
|
32
|
+
proceeding = ECFS::ProceedingsQuery.new.tap do |q|
|
33
|
+
q.eq("proceeding_number", "12-375")
|
34
|
+
end.get
|
35
|
+
#=>
|
36
|
+
{
|
37
|
+
"bureau_name" => "Wireline Competition Bureau",
|
38
|
+
"subject" =>
|
39
|
+
"Implementation of the Pay Telephone Reclassification and Compensation Provisions of the Telecommunications Act of 1996 et al.",
|
40
|
+
"prepared_by" => "Aleta.Bowers",
|
41
|
+
"date_created" => "12/26/2012",
|
42
|
+
"status" => "Open",
|
43
|
+
"total_filings" => "292",
|
44
|
+
"filings_in_last_30_days" => "58"
|
45
|
+
}
|
46
|
+
```
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/ecfs.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ecfs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ecfs"
|
8
|
+
spec.version = ECFS::VERSION
|
9
|
+
spec.authors = ["Alan deLevie"]
|
10
|
+
spec.email = ["adelevie@gmail.com"]
|
11
|
+
spec.description = %q{ECFS provides a set of utilities for scraping FCC rulemakings}
|
12
|
+
spec.summary = %q{ECFS helps you obtain comments and other filings from the FCC's Electronic Comment Filing System}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "mechanize"
|
25
|
+
spec.add_dependency "pry"
|
26
|
+
end
|
data/lib/ecfs.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require "mechanize"
|
2
|
+
|
3
|
+
module ECFS
|
4
|
+
|
5
|
+
class ProceedingsQuery
|
6
|
+
attr_reader :constraints
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@constraints = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def eq(field, value)
|
13
|
+
@constraints[field] = value
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def constraints_dictionary
|
18
|
+
{
|
19
|
+
"docket_number" => "name",
|
20
|
+
"bureau_code" => "bureauCode",
|
21
|
+
"subject" => "subject",
|
22
|
+
"bureau_id" => "bureauIdentificationNumber",
|
23
|
+
"applicant" => "application",
|
24
|
+
"filed_by" => "filedBy",
|
25
|
+
"recent_filings" => "__checkbox_recentFilingsRequired",
|
26
|
+
"open_status" => "openStatus",
|
27
|
+
"created_after" => "created.minDate",
|
28
|
+
"created_before" => "created.maxDate",
|
29
|
+
"closed_after" => "closed.minDate",
|
30
|
+
"closed_before" => "closed.maxDate",
|
31
|
+
"callsign" => "callsign",
|
32
|
+
"channel" => "channel",
|
33
|
+
"rule_section" => "ruleSection",
|
34
|
+
"page_number" => "pageNumber"
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def format_constraint(constraint)
|
39
|
+
constraints_dictionary[constraint]
|
40
|
+
end
|
41
|
+
|
42
|
+
def query_string
|
43
|
+
@constraints.keys.map do |constraint|
|
44
|
+
format_constraint(constraint) + "=" + @constraints[constraint]
|
45
|
+
end.join("&")
|
46
|
+
end
|
47
|
+
|
48
|
+
def url
|
49
|
+
base = "http://apps.fcc.gov/ecfs/proceeding_search/execute"
|
50
|
+
|
51
|
+
"#{base}?#{query_string}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def get
|
55
|
+
if @constraints["docket_number"]
|
56
|
+
scrape_proceedings_page
|
57
|
+
else
|
58
|
+
scrape_results_page
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def scrape_proceedings_page
|
65
|
+
agent = Mechanize.new
|
66
|
+
page = agent.get(url)
|
67
|
+
container = []
|
68
|
+
page.search("div").select do |d|
|
69
|
+
d.attributes["class"].nil? == false
|
70
|
+
end.select do |d|
|
71
|
+
d.attributes["class"].text == "wwgrp"
|
72
|
+
end.each do |node|
|
73
|
+
node.search("span").each do |span|
|
74
|
+
search = span.search("label")
|
75
|
+
pair = []
|
76
|
+
if search.length > 0
|
77
|
+
key = search.first.children.first.text.lstrip.rstrip.split(":")[0].gsub(" ", "_").downcase
|
78
|
+
pair << key
|
79
|
+
else
|
80
|
+
value = span.text.lstrip.rstrip
|
81
|
+
value.gsub!(",", "") if value.is_a?(String)
|
82
|
+
pair << value
|
83
|
+
end
|
84
|
+
container << pair
|
85
|
+
end
|
86
|
+
end
|
87
|
+
hash = {}
|
88
|
+
container.each_slice(2) do |chunk|
|
89
|
+
hash.merge!({chunk[0][0] => chunk[1][0]})
|
90
|
+
end
|
91
|
+
|
92
|
+
hash
|
93
|
+
end
|
94
|
+
|
95
|
+
def scrape_results_page
|
96
|
+
raise "Parsing result pages is not yet supported."
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
data/lib/ecfs/version.rb
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
require 'test/unit'
|
13
|
+
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
|
+
require 'ecfs'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "pp"
|
3
|
+
|
4
|
+
class TestProceedingsQuery < Test::Unit::TestCase
|
5
|
+
def test_add_constraint
|
6
|
+
proceedings_query = ECFS::ProceedingsQuery.new
|
7
|
+
proceedings_query.eq("docket_number", "12-375")
|
8
|
+
proceedings_query.constraints
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_constraints_dictionary
|
12
|
+
proceedings_query = ECFS::ProceedingsQuery.new
|
13
|
+
dictionary = proceedings_query.constraints_dictionary
|
14
|
+
assert_equal Hash, dictionary.class
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_query_string
|
18
|
+
proceedings_query = ECFS::ProceedingsQuery.new
|
19
|
+
proceedings_query.eq("docket_number", "12-375")
|
20
|
+
proceedings_query.eq("subject", "phones")
|
21
|
+
assert_equal proceedings_query.query_string, "name=12-375&subject=phones"
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_url
|
25
|
+
proceedings_query = ECFS::ProceedingsQuery.new
|
26
|
+
proceedings_query.eq("bureau_code", "WC")
|
27
|
+
proceedings_query.eq("subject", "phones")
|
28
|
+
url = "http://apps.fcc.gov/ecfs/proceeding_search/execute?bureauCode=WC&subject=phones"
|
29
|
+
assert_equal proceedings_query.url, url
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_get_proceeding_info
|
33
|
+
proceedings_query = ECFS::ProceedingsQuery.new
|
34
|
+
proceedings_query.eq("docket_number", "12-375")
|
35
|
+
results = proceedings_query.get
|
36
|
+
%w[
|
37
|
+
bureau_name subject date_created status
|
38
|
+
total_filings filings_in_last_30_days
|
39
|
+
].each do |key|
|
40
|
+
assert results.keys.include?(key)
|
41
|
+
end
|
42
|
+
pp results
|
43
|
+
end
|
44
|
+
|
45
|
+
# TODO: Implement proceeding search result pages
|
46
|
+
def test_get_proceeding_search_results
|
47
|
+
proceedings_query = ECFS::ProceedingsQuery.new
|
48
|
+
proceedings_query.eq("bureau_code", "WB")
|
49
|
+
assert_raise RuntimeError do
|
50
|
+
proceedings_query.get
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ecfs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alan deLevie
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: mechanize
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: ECFS provides a set of utilities for scraping FCC rulemakings
|
79
|
+
email:
|
80
|
+
- adelevie@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .travis.yml
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- ecfs.gemspec
|
92
|
+
- lib/ecfs.rb
|
93
|
+
- lib/ecfs/proceedings_query.rb
|
94
|
+
- lib/ecfs/version.rb
|
95
|
+
- test/helper.rb
|
96
|
+
- test/test_proceedings_query.rb
|
97
|
+
homepage: ''
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.24
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: ECFS helps you obtain comments and other filings from the FCC's Electronic
|
122
|
+
Comment Filing System
|
123
|
+
test_files:
|
124
|
+
- test/helper.rb
|
125
|
+
- test/test_proceedings_query.rb
|
126
|
+
has_rdoc:
|