lakes 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/lakes/texas.rb +24 -29
- data/lib/lakes.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2234be1dd9e85792994fd9943a08ecf2768128c2
|
4
|
+
data.tar.gz: 727102c0fa0e2f682ac22bd45bcde550a244f9e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3182d5719093b93edfc3e44a05d831c689e263321be8dd639582a22dcc4026e316e636206c0543989012042d01eb41f62bb3b65447d443debc64aa46a52ab1e
|
7
|
+
data.tar.gz: 4ef88d976d9d2d8fec82ecb7bf3735158ad4fe84e45f53a4ff01da13dd586035a51f944c2b64c345b94aea582d49578580a9519ce565e90de1e7524973b6ac14
|
data/.gitignore
CHANGED
data/lib/lakes/texas.rb
CHANGED
@@ -15,8 +15,7 @@ module Lakes
|
|
15
15
|
return @lake_data.keys unless @lake_data.empty?
|
16
16
|
|
17
17
|
base_url = 'http://tpwd.texas.gov/fishboat/fish/recreational/lakes/'
|
18
|
-
|
19
|
-
content = Net::HTTP.get(uri)
|
18
|
+
content = http_get("#{base_url}lakelist.phtml")
|
20
19
|
html_doc = Nokogiri::HTML(content)
|
21
20
|
|
22
21
|
# remove elements not needed to make parsing easier
|
@@ -42,9 +41,7 @@ module Lakes
|
|
42
41
|
protected
|
43
42
|
|
44
43
|
def parse_lake_details(lake_data)
|
45
|
-
|
46
|
-
content = Net::HTTP.get(uri).encode('UTF-8', 'Windows-1252')
|
47
|
-
|
44
|
+
content = http_get(lake_data[:details_uri] + '/')
|
48
45
|
html_doc = Nokogiri::HTML(content)
|
49
46
|
main_div = html_doc.at('div#maincontent')
|
50
47
|
|
@@ -103,39 +100,27 @@ module Lakes
|
|
103
100
|
end
|
104
101
|
|
105
102
|
def parse_fishing_regulations(main_div, lake_data)
|
106
|
-
|
107
|
-
content = data.try(:next_element).try(:to_html)
|
108
|
-
lake_data[:fishing_regulations] = content
|
103
|
+
process_simple_section(main_div, lake_data, 'Fishing Regulations', :fishing_regulations, true)
|
109
104
|
end
|
110
105
|
|
111
106
|
def parse_lake_maps(main_div, lake_data)
|
112
|
-
|
113
|
-
content = data.try(:next_element).try(:text)
|
114
|
-
lake_data[:lake_maps] = content
|
107
|
+
process_simple_section(main_div, lake_data, 'Lake Maps', :lake_maps, false)
|
115
108
|
end
|
116
109
|
|
117
110
|
def parse_lake_characteristics(main_div, lake_data)
|
118
|
-
|
119
|
-
content = data.try(:next_element).try(:text)
|
120
|
-
lake_data[:lake_characteristics] = content
|
111
|
+
process_simple_section(main_div, lake_data, 'Lake Characteristics', :lake_characteristics, false)
|
121
112
|
end
|
122
113
|
|
123
114
|
def parse_water_conditions(main_div, lake_data)
|
124
|
-
|
125
|
-
content = data.try(:next_element).try(:to_html)
|
126
|
-
lake_data[:water_conditions] = content
|
115
|
+
process_simple_section(main_div, lake_data, 'Water Conditions', :water_conditions, true)
|
127
116
|
end
|
128
117
|
|
129
118
|
def parse_reservoir_controlling_authority(main_div, lake_data)
|
130
|
-
|
131
|
-
content = data.try(:next_element).try(:text)
|
132
|
-
lake_data[:reservoir_controlling_authority] = content
|
119
|
+
process_simple_section(main_div, lake_data, 'Reservoir Controlling Authority', :reservoir_controlling_authority, false)
|
133
120
|
end
|
134
121
|
|
135
122
|
def parse_aquatic_vegetation(main_div, lake_data)
|
136
|
-
|
137
|
-
content = data.try(:next_element).try(:text)
|
138
|
-
lake_data[:aquatic_vegetation] = content
|
123
|
+
process_simple_section(main_div, lake_data, 'Aquatic Vegetation', :aquatic_vegetation, false)
|
139
124
|
end
|
140
125
|
|
141
126
|
def parse_predominant_fish_species(main_div, lake_data)
|
@@ -163,8 +148,7 @@ module Lakes
|
|
163
148
|
uri = link['href']
|
164
149
|
lake_data[:stocking_history_uri] = convert_relative_href(uri, lake_data[:details_uri])
|
165
150
|
|
166
|
-
|
167
|
-
content = Net::HTTP.get(uri).encode('UTF-8', 'Windows-1252')
|
151
|
+
content = http_get(lake_data[:stocking_history_uri])
|
168
152
|
stocking_history_doc = Nokogiri::HTML(content)
|
169
153
|
|
170
154
|
stocking_history_table = stocking_history_doc.at('div#maincontent table')
|
@@ -184,8 +168,7 @@ module Lakes
|
|
184
168
|
uri = link['href']
|
185
169
|
lake_data[:current_fishing_report_uri] = convert_relative_href(uri, lake_data[:details_uri])
|
186
170
|
|
187
|
-
|
188
|
-
content = Net::HTTP.get(uri).encode('UTF-8', 'Windows-1252')
|
171
|
+
content = http_get(lake_data[:current_fishing_report_uri])
|
189
172
|
current_fishing_report_doc = Nokogiri::HTML(content)
|
190
173
|
current_fishing_report_dl = current_fishing_report_doc.at('div.row.report div.container dl')
|
191
174
|
|
@@ -206,8 +189,7 @@ module Lakes
|
|
206
189
|
uri = link['href']
|
207
190
|
lake_data[:fishing_records_uri] = convert_relative_href(uri, lake_data[:details_uri])
|
208
191
|
|
209
|
-
|
210
|
-
content = Net::HTTP.get(uri).encode('UTF-8', 'Windows-1252')
|
192
|
+
content = http_get(lake_data[:fishing_records_uri])
|
211
193
|
lake_records_doc = Nokogiri::HTML(content)
|
212
194
|
lake_records_main_div = lake_records_doc.at('div#maincontent')
|
213
195
|
|
@@ -286,5 +268,18 @@ module Lakes
|
|
286
268
|
value = value.strip.gsub(nbsp, '')
|
287
269
|
value.empty? ? nil : value
|
288
270
|
end
|
271
|
+
|
272
|
+
def process_simple_section(main_div, lake_data, section_title, data_name, html)
|
273
|
+
data = main_div.xpath("//h6[contains(text(), \"#{section_title}\")]").first
|
274
|
+
element_type_function = html ? :to_html : :text
|
275
|
+
content = data.try(:next_element).try(element_type_function)
|
276
|
+
lake_data[data_name] = content
|
277
|
+
end
|
278
|
+
|
279
|
+
# texas lake pages are encoded in Windows-1252 :(
|
280
|
+
def http_get(url)
|
281
|
+
uri = URI(url)
|
282
|
+
Net::HTTP.get(uri).encode('UTF-8', 'Windows-1252')
|
283
|
+
end
|
289
284
|
end
|
290
285
|
end
|
data/lib/lakes.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lakes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Sherman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|