Module: ECFS::Filings

Defined in:
lib/ecfs.rb

Constant Summary collapse

ATTRS =
[
  :docket, :filer, :lawfirm, :received,
  :posted, :exparte, :type, :pages
]

Class Method Summary collapse

Class Method Details



162
163
164
165
166
167
168
169
170
171
172
# File 'lib/ecfs.rb', line 162

def self.get_document_links(url: url)
  doc = Nokogiri::HTML(open(url))
  xpath = "//*[@id=\"documents.link\"]"
  links = doc.xpath(xpath).search('a')

  links.map do |link|
    id = link.attributes["href"].value.split('?id=')[1]

    "http://apps.fcc.gov/ecfs/document/view?id=#{id}"
  end
end

.search(docket: nil, size: 1000, start: 0, order: 'asc') ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/ecfs.rb', line 174

def self.search(docket: nil, size: 1000, start: 0, order: 'asc')
  url = "http://apps.fcc.gov/ecfs/comment_search_solr/doSearch?proceeding=#{docket}&dir=#{order}&start=#{start}&size=#{size}"
  doc = Nokogiri::HTML(open(url))
  xpath = "//*[@id='yui-main']/div/div[4]"
  table = doc.xpath(xpath).children[1]
  rows = table.search('tr')
  rows.shift

  filings = []
  rows.each do |row|
    row_hash = {}
    cols = row.search('td')

    cols.each_with_index do |col, i|
      attribute = ECFS::Filings::ATTRS[i]
      row_hash[attribute] = col.text.strip

      # get the url
      if attribute == :filer
        path = col.search('a').first.attributes["href"].value
        id = path.split('?id=')[1]
        url = "http://apps.fcc.gov/ecfs/comment/view?id=#{id}"
        row_hash[:url] = url
      end
    end

    # cast dates and int
    row_hash[:received] = DateTime.parse(row_hash[:received]).to_s
    row_hash[:posted] = DateTime.parse(row_hash[:posted]).to_s
    row_hash[:pages] = row_hash[:pages].to_i

    filings << row_hash
  end

  filings
end