87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/ecfs.rb', line 87
def self.search(docket: nil, da: nil, fcc: nil, report: nil, file: nil, fcc_rcd_vol: nil, fcc_rcd_page: nil)
uri = URI.parse("https://apps.fcc.gov/edocs_public/Query.do?mode=advanced&rpt=cond")
params = {
'fccNo' => fcc,
'daNo' => da,
'fileNo' => file,
'docket' => docket,
'reportNo' => report,
'fccRecordVol' => fcc_rcd_vol,
'fccRecordPage' => fcc_rcd_page
}
params.reject! {|_k,v| v.nil?}
url = 'https://apps.fcc.gov/edocs_public/Query.do?mode=advance&rpt=cond'
response = Unirest.post url, parameters: params
doc = Nokogiri::HTML(response.raw_body)
tables = doc.css('table.tableWithOutBorder').children.css('table.tableWithOutBorder')
results = tables[2].css('table.tableWithBorder')
results.map do |result|
links = result.search('a').to_a
links.shift
links = links.map do |link|
path = link.attributes["href"].value
"https://apps.fcc.gov/edocs_public/#{path}"
end
word = links.select {|link| link.end_with?('.doc', '.docx')}
pdf = links.select {|link| link.end_with?('.pdf')}
txt = links.select {|link| link.end_with?('.txt')}
rows = result.search('tr')
{
title: rows[0].text.strip,
released: rows[1].text.strip.split(': ')[1],
description: rows[2].text.strip.split('Description: ')[1],
word: word,
pdf: pdf,
txt: txt
}.reject {|_k,v| v.nil?}
end
end
|