run-swim-hike-nyc 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/NOTES.markdown +10 -0
- data/README.md +45 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/run-swim-hike +5 -0
- data/bin/setup +8 -0
- data/lib/run-swim-hike-nyc.rb +11 -0
- data/lib/run-swim-hike-nyc/cli.rb +231 -0
- data/lib/run-swim-hike-nyc/hike.rb +113 -0
- data/lib/run-swim-hike-nyc/hike_scraper.rb +142 -0
- data/lib/run-swim-hike-nyc/run.rb +114 -0
- data/lib/run-swim-hike-nyc/run_scraper.rb +197 -0
- data/lib/run-swim-hike-nyc/swim.rb +138 -0
- data/lib/run-swim-hike-nyc/swim_scraper.rb +169 -0
- data/lib/run-swim-hike-nyc/version.rb +3 -0
- data/run-swim-hike-nyc.gemspec +35 -0
- metadata +164 -0
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
class HikeScraper
|
6
|
+
|
7
|
+
attr_accessor :prop_id, :names, :location, :park_name, :length, :difficulty, :other_details, :accessible, :borough
|
8
|
+
@@hike = {}
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@prop_id = []
|
12
|
+
@names = []
|
13
|
+
@location = []
|
14
|
+
@park_name = []
|
15
|
+
@length = []
|
16
|
+
@difficulty = []
|
17
|
+
@other_details = []
|
18
|
+
@accessible = []
|
19
|
+
@borough = []
|
20
|
+
end
|
21
|
+
|
22
|
+
def call
|
23
|
+
collect_and_create
|
24
|
+
end
|
25
|
+
|
26
|
+
def collect_and_create
|
27
|
+
xml = open("http://www.nycgovparks.org/bigapps/DPR_Hiking_001.xml")
|
28
|
+
doc = Nokogiri::HTML(xml)
|
29
|
+
facilities = doc.xpath("//facility")
|
30
|
+
prop_id = facilities.xpath("//prop_id")
|
31
|
+
names = facilities.xpath("//name")
|
32
|
+
location = facilities.xpath("//location")
|
33
|
+
park_name = facilities.xpath("//park_name")
|
34
|
+
length = facilities.xpath("//length")
|
35
|
+
difficulty = facilities.xpath("//difficulty")
|
36
|
+
other_details = facilities.xpath("//other_details")
|
37
|
+
accessible = facilities.xpath("//accessible")
|
38
|
+
|
39
|
+
prop_id.each do |id|
|
40
|
+
@prop_id << id.text.to_s
|
41
|
+
@@hike[:prop_id] = @prop_id
|
42
|
+
end
|
43
|
+
|
44
|
+
names.each do |name|
|
45
|
+
@names << name.text.to_s
|
46
|
+
@@hike[:names] = @names
|
47
|
+
end
|
48
|
+
|
49
|
+
location.each do |location|
|
50
|
+
@location << location.text.to_s
|
51
|
+
@@hike[:location] = @location
|
52
|
+
end
|
53
|
+
|
54
|
+
park_name.each do |park_name|
|
55
|
+
@park_name << park_name.text.to_s
|
56
|
+
@@hike[:park_name] = @park_name
|
57
|
+
end
|
58
|
+
|
59
|
+
length.each do |length|
|
60
|
+
@length << length.text.to_s
|
61
|
+
@@hike[:length] = @length
|
62
|
+
end
|
63
|
+
|
64
|
+
difficulty.each do |difficulty|
|
65
|
+
@difficulty << difficulty.text.to_s
|
66
|
+
@@hike[:difficulty] = @difficulty
|
67
|
+
end
|
68
|
+
|
69
|
+
other_details.each do |other_details|
|
70
|
+
@other_details << other_details.text.to_s
|
71
|
+
@@hike[:other_details] = @other_details
|
72
|
+
end
|
73
|
+
|
74
|
+
accessible.each do |accessible|
|
75
|
+
@accessible << accessible.text.to_s
|
76
|
+
@@hike[:accessible] = @accessible
|
77
|
+
end
|
78
|
+
|
79
|
+
@@hike[:names].each do |name|
|
80
|
+
temp = Hike.new(name)
|
81
|
+
end
|
82
|
+
|
83
|
+
counter = 0
|
84
|
+
Hike.all.each do |instance|
|
85
|
+
instance.prop_id = @@hike[:prop_id][counter]
|
86
|
+
if instance.prop_id.start_with?("X")
|
87
|
+
instance.borough = "Bronx"
|
88
|
+
elsif instance.prop_id.start_with?("B")
|
89
|
+
instance.borough = "Brooklyn"
|
90
|
+
elsif instance.prop_id.start_with?("M")
|
91
|
+
instance.borough = "Manhattan"
|
92
|
+
elsif instance.prop_id.start_with?("Q")
|
93
|
+
instance.borough = "Queens"
|
94
|
+
elsif instance.prop_id.start_with?("R")
|
95
|
+
instance.borough = "Staten Island"
|
96
|
+
end
|
97
|
+
counter += 1
|
98
|
+
end
|
99
|
+
|
100
|
+
counter = 0
|
101
|
+
Hike.all.each do |instance|
|
102
|
+
instance.location = @@hike[:location][counter]
|
103
|
+
counter += 1
|
104
|
+
end
|
105
|
+
|
106
|
+
counter = 0
|
107
|
+
Hike.all.each do |instance|
|
108
|
+
instance.park_name = @@hike[:park_name][counter]
|
109
|
+
counter += 1
|
110
|
+
end
|
111
|
+
|
112
|
+
counter = 0
|
113
|
+
Hike.all.each do |instance|
|
114
|
+
instance.length = @@hike[:length][counter]
|
115
|
+
counter += 1
|
116
|
+
end
|
117
|
+
|
118
|
+
counter = 0
|
119
|
+
Hike.all.each do |instance|
|
120
|
+
instance.difficulty = @@hike[:difficulty][counter]
|
121
|
+
counter += 1
|
122
|
+
end
|
123
|
+
|
124
|
+
counter = 0
|
125
|
+
Hike.all.each do |instance|
|
126
|
+
instance.other_details = @@hike[:other_details][counter]
|
127
|
+
counter += 1
|
128
|
+
end
|
129
|
+
|
130
|
+
counter = 0
|
131
|
+
Hike.all.each do |instance|
|
132
|
+
instance.accessible = @@hike[:accessible][counter]
|
133
|
+
counter += 1
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def all
|
138
|
+
@@hike
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'launchy'
|
4
|
+
|
5
|
+
class Run
|
6
|
+
attr_accessor :borough, :name, :prop_id, :size, :track_type, :location, :lat, :lon
|
7
|
+
@@farewell = ["Have a nice day!", "Take care of yourself!", "You'll never regret some good excercise!", "Have fun!", "Thanks for checking us out!", "Keep running, swimming and hiking!", ":)"]
|
8
|
+
@@all = []
|
9
|
+
@@parks = []
|
10
|
+
|
11
|
+
def initialize(name)
|
12
|
+
@name = name
|
13
|
+
@@all << self
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.all
|
17
|
+
@@all
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.parks
|
21
|
+
@@parks
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.reset
|
25
|
+
clear
|
26
|
+
@@all = []
|
27
|
+
@@parks = []
|
28
|
+
RunSwimHike::CLI.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.clear
|
32
|
+
print "\e[2J\e[f"
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.spinny
|
36
|
+
n=0
|
37
|
+
a=["-","\\","|","/"].cycle do |a|
|
38
|
+
print a
|
39
|
+
print "\b"
|
40
|
+
n+=1
|
41
|
+
sleep 0.1
|
42
|
+
break if (n % 6).zero?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.quit
|
47
|
+
puts " \n"
|
48
|
+
abort("#{@@farewell.sample} \n ")
|
49
|
+
end
|
50
|
+
|
51
|
+
####### RUN LOGIC #######
|
52
|
+
|
53
|
+
def self.load_borough(cli_input)
|
54
|
+
all.each do |track|
|
55
|
+
if track.borough == cli_input
|
56
|
+
parks << track unless parks.include?(track)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
display_borough("#{parks[0].borough}")
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.display_borough(borough)
|
63
|
+
spinny
|
64
|
+
index = 0
|
65
|
+
puts " \nHere are the Running Tracks in #{borough}: \n "
|
66
|
+
spinny
|
67
|
+
parks.each do |track|
|
68
|
+
if track.borough == borough
|
69
|
+
parks << track unless parks.include?(track)
|
70
|
+
puts "#{index+1}. #{track.name} - #{track.location}"
|
71
|
+
index += 1
|
72
|
+
sleep(0.04)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
spinny
|
76
|
+
puts " \nSelect a number for more information:"
|
77
|
+
spinny
|
78
|
+
input = gets.strip
|
79
|
+
if input.to_i != 0 && input.to_i <= parks.size
|
80
|
+
park_select(input)
|
81
|
+
elsif input == "exit"
|
82
|
+
quit
|
83
|
+
elsif input == "reset"
|
84
|
+
reset
|
85
|
+
else
|
86
|
+
clear
|
87
|
+
puts " \n--------------------------------------\nPlease choose a number from the menu:\n--------------------------------------"
|
88
|
+
display_borough("#{parks[0].borough}")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def self.park_select(cli_input)
|
94
|
+
clear
|
95
|
+
display = parks[cli_input.to_i-1]
|
96
|
+
puts " \n#{display.name}: \n \nBorough: #{display.borough} \nLocation: #{display.location} \nSize: #{display.size} mile(s)\nRunning Track Type: #{display.track_type} "
|
97
|
+
puts " \nOptions:\n'open' to display in Google Maps\n'back' to see search results in #{display.borough}\n'reset' to return to main menu"
|
98
|
+
input = gets.strip
|
99
|
+
if input == "open"
|
100
|
+
Launchy.open("https://www.google.com/maps/place/#{display.name}/@#{display.lat},#{display.lon},18z")
|
101
|
+
park_select(cli_input)
|
102
|
+
elsif input == "back"
|
103
|
+
clear
|
104
|
+
display_borough("#{display.borough}")
|
105
|
+
elsif input == "reset"
|
106
|
+
reset
|
107
|
+
elsif input == "exit"
|
108
|
+
quit
|
109
|
+
else
|
110
|
+
park_select(cli_input)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
class RunScraper
|
6
|
+
attr_accessor :names, :prop_id, :size, :location, :boroughs, :lat, :lon, :track_type
|
7
|
+
@@run = {}
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@names = []
|
11
|
+
@prop_id = []
|
12
|
+
@size = []
|
13
|
+
@location = []
|
14
|
+
@track_type = []
|
15
|
+
@lat = []
|
16
|
+
@lon = []
|
17
|
+
@boroughs = {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def call
|
21
|
+
collect_and_create
|
22
|
+
end
|
23
|
+
|
24
|
+
def collect_and_create
|
25
|
+
xml = open("http://www.nycgovparks.org/bigapps/DPR_RunningTracks_001.xml")
|
26
|
+
doc = Nokogiri::HTML(xml)
|
27
|
+
facilities = doc.xpath("//facility")
|
28
|
+
names = facilities.xpath("//name")
|
29
|
+
prop_id = facilities.xpath("//prop_id")
|
30
|
+
size = facilities.xpath("//size")
|
31
|
+
location = facilities.xpath("//location")
|
32
|
+
track_type = facilities.xpath("//runningtracks_type")
|
33
|
+
lat = facilities.xpath("//lat")
|
34
|
+
lon = facilities.xpath("//lon")
|
35
|
+
|
36
|
+
|
37
|
+
names.each do |name|
|
38
|
+
@names << name.text.to_s
|
39
|
+
@@run[:names] = @names
|
40
|
+
end
|
41
|
+
|
42
|
+
prop_id.each do |id|
|
43
|
+
@prop_id << id.text.to_s
|
44
|
+
@@run[:prop_id] = @prop_id
|
45
|
+
end
|
46
|
+
|
47
|
+
size.each do |size|
|
48
|
+
@size << size.text.to_s
|
49
|
+
@@run[:size] = @size
|
50
|
+
end
|
51
|
+
|
52
|
+
location.each do |location|
|
53
|
+
@location << location.text.to_s
|
54
|
+
@@run[:location] = @location
|
55
|
+
end
|
56
|
+
|
57
|
+
track_type.each do |track_type|
|
58
|
+
@track_type << track_type.text.to_s
|
59
|
+
@@run[:track_type] = @track_type
|
60
|
+
end
|
61
|
+
|
62
|
+
lat.each do |lat|
|
63
|
+
@lat << lat.text.to_s
|
64
|
+
@@run[:lat] = @lat
|
65
|
+
end
|
66
|
+
|
67
|
+
lon.each do |lon|
|
68
|
+
@lon << lon.text.to_s
|
69
|
+
@@run[:lon] = @lon
|
70
|
+
end
|
71
|
+
|
72
|
+
@@run[:names].each do |name|
|
73
|
+
temp = Run.new(name)
|
74
|
+
end
|
75
|
+
|
76
|
+
counter = 0
|
77
|
+
Run.all.each do |instance|
|
78
|
+
instance.prop_id = @@run[:prop_id][counter]
|
79
|
+
if instance.prop_id.start_with?("X")
|
80
|
+
instance.borough = "Bronx"
|
81
|
+
elsif instance.prop_id.start_with?("B")
|
82
|
+
instance.borough = "Brooklyn"
|
83
|
+
elsif instance.prop_id.start_with?("M")
|
84
|
+
instance.borough = "Manhattan"
|
85
|
+
elsif instance.prop_id.start_with?("Q")
|
86
|
+
instance.borough = "Queens"
|
87
|
+
elsif instance.prop_id.start_with?("R")
|
88
|
+
instance.borough = "Staten Island"
|
89
|
+
end
|
90
|
+
counter += 1
|
91
|
+
end
|
92
|
+
|
93
|
+
counter = 0
|
94
|
+
Run.all.each do |instance|
|
95
|
+
instance.size = @@run[:size][counter]
|
96
|
+
counter += 1
|
97
|
+
end
|
98
|
+
|
99
|
+
counter = 0
|
100
|
+
Run.all.each do |instance|
|
101
|
+
instance.location = @@run[:location][counter]
|
102
|
+
counter += 1
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
counter = 0
|
107
|
+
Run.all.each do |instance|
|
108
|
+
instance.track_type = @@run[:track_type][counter]
|
109
|
+
counter += 1
|
110
|
+
end
|
111
|
+
|
112
|
+
counter = 0
|
113
|
+
Run.all.each do |instance|
|
114
|
+
instance.lat = @@run[:lat][counter]
|
115
|
+
counter += 1
|
116
|
+
end
|
117
|
+
|
118
|
+
counter = 0
|
119
|
+
Run.all.each do |instance|
|
120
|
+
instance.lon = @@run[:lon][counter]
|
121
|
+
counter += 1
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
def all
|
128
|
+
@@run
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
# def index_boroughs
|
133
|
+
# bronx = []
|
134
|
+
# brooklyn = []
|
135
|
+
# manhattan = []
|
136
|
+
# queens = []
|
137
|
+
# staten_island = []
|
138
|
+
|
139
|
+
# hash = Hash[@prop_id.map.with_index.to_a]
|
140
|
+
# hash.each do |prop_id, array_position|
|
141
|
+
# if prop_id.start_with?("X")
|
142
|
+
# bronx << array_position
|
143
|
+
# elsif prop_id.start_with?("B")
|
144
|
+
# brooklyn << array_position
|
145
|
+
# elsif prop_id.start_with?("M")
|
146
|
+
# manhattan << array_position
|
147
|
+
# elsif prop_id.start_with?("Q")
|
148
|
+
# queens << array_position
|
149
|
+
# elsif prop_id.start_with?("R")
|
150
|
+
# staten_island << array_position
|
151
|
+
# end
|
152
|
+
# end
|
153
|
+
# @boroughs[:bronx] = bronx
|
154
|
+
# @boroughs[:brooklyn] = brooklyn
|
155
|
+
# @boroughs[:manhattan] = manhattan
|
156
|
+
# @boroughs[:queens] = queens
|
157
|
+
# @boroughs[:staten_island] = staten_island
|
158
|
+
# end
|
159
|
+
|
160
|
+
# def bronx
|
161
|
+
# @boroughs[:bronx].each_with_index do |array_position, i|
|
162
|
+
# puts "#{i+1}: #{@names[array_position]}"
|
163
|
+
# end
|
164
|
+
# end
|
165
|
+
|
166
|
+
# def brooklyn
|
167
|
+
# @boroughs[:brooklyn].each_with_index do |array_position, i|
|
168
|
+
# puts "#{i+1}: #{@names[array_position]}"
|
169
|
+
# end
|
170
|
+
# end
|
171
|
+
|
172
|
+
# def manhattan
|
173
|
+
# @boroughs[:manhattan].each_with_index do |array_position, i|
|
174
|
+
# puts "#{i+1}: #{@names[array_position]}"
|
175
|
+
# end
|
176
|
+
# end
|
177
|
+
|
178
|
+
# def queens
|
179
|
+
# @boroughs[:queens].each_with_index do |array_position, i|
|
180
|
+
# puts "#{i+1}: #{@names[array_position]}"
|
181
|
+
# end
|
182
|
+
# end
|
183
|
+
|
184
|
+
# def staten_island
|
185
|
+
# @boroughs[:staten_island].each_with_index do |array_position, i|
|
186
|
+
# puts "#{i+1}: #{@names[array_position]}"
|
187
|
+
# end
|
188
|
+
# end
|
189
|
+
|
190
|
+
|
191
|
+
# def list_names
|
192
|
+
# @names.each_with_index do |name, i|
|
193
|
+
# puts "#{i+1}: #{name}"
|
194
|
+
# end
|
195
|
+
# end
|
196
|
+
|
197
|
+
end
|