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,138 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'launchy'
|
4
|
+
|
5
|
+
class Swim
|
6
|
+
attr_accessor :prop_id, :name, :location, :phone, :pools_type, :setting, :size, :accessible, :borough, :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
|
+
####### SWIM LOGIC #######
|
52
|
+
|
53
|
+
def self.load_borough(cli_input)
|
54
|
+
puts " \nPlease choose a setting: \n1. Indoor \n2. Outdoor"
|
55
|
+
input = gets.strip
|
56
|
+
|
57
|
+
if input.to_s == "1"
|
58
|
+
all.each do |pool|
|
59
|
+
if pool.borough == cli_input && pool.setting == "Indoor"
|
60
|
+
parks << pool unless parks.include?(pool)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
if parks.size != 0
|
64
|
+
display_borough(cli_input, "Indoor")
|
65
|
+
else
|
66
|
+
puts " \nSorry! There are no Indoor pools at the moment."
|
67
|
+
load_borough(cli_input)
|
68
|
+
end
|
69
|
+
elsif input.to_s == "2"
|
70
|
+
all.each do |pool|
|
71
|
+
if pool.borough == cli_input && pool.setting == "Outdoor"
|
72
|
+
parks << pool unless parks.include?(pool)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
display_borough(cli_input, "Outdoor")
|
76
|
+
elsif input == "exit"
|
77
|
+
quit
|
78
|
+
elsif input == "reset"
|
79
|
+
reset
|
80
|
+
else
|
81
|
+
clear
|
82
|
+
puts " \n--------------------------------------\nPlease choose a number from the menu:\n--------------------------------------"
|
83
|
+
load_borough(cli_input)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.display_borough(borough, setting)
|
88
|
+
spinny
|
89
|
+
index = 0
|
90
|
+
puts " \nHere are the #{setting} Swimming Pools in #{borough}: \n "
|
91
|
+
spinny
|
92
|
+
parks.each do |pool|
|
93
|
+
if pool.borough == borough && pool.setting == setting
|
94
|
+
puts "#{index+1}. #{pool.name} - #{pool.location}"
|
95
|
+
index += 1
|
96
|
+
sleep(0.04)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
spinny
|
100
|
+
puts " \nSelect a number for more information:"
|
101
|
+
spinny
|
102
|
+
input = gets.strip
|
103
|
+
if input.to_i != 0 && input.to_i <= index
|
104
|
+
park_select(input)
|
105
|
+
elsif input == "exit"
|
106
|
+
quit
|
107
|
+
elsif input == "reset"
|
108
|
+
reset
|
109
|
+
else
|
110
|
+
clear
|
111
|
+
puts " \n--------------------------------------\nPlease choose a number from the menu:\n--------------------------------------"
|
112
|
+
display_borough(borough, setting)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def self.park_select(cli_input)
|
118
|
+
clear
|
119
|
+
display = parks[cli_input.to_i-1]
|
120
|
+
puts " \n#{display.name}: \n \nBorough: #{display.borough} \nLocation: #{display.location} \nPhone: #{display.phone} \nPool Type: #{display.pools_type} \nSetting: #{display.setting} \nSize: #{display.size} \nWheelchair Accessible: #{display.accessible}"
|
121
|
+
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"
|
122
|
+
input = gets.strip
|
123
|
+
if input == "open"
|
124
|
+
Launchy.open("https://www.google.com/maps/place/#{display.name}/@#{display.lat},#{display.lon},18z")
|
125
|
+
park_select(cli_input)
|
126
|
+
elsif input == "back"
|
127
|
+
clear
|
128
|
+
display_borough("#{display.borough}", "#{display.setting}")
|
129
|
+
elsif input == "reset"
|
130
|
+
reset
|
131
|
+
elsif input == "exit"
|
132
|
+
quit
|
133
|
+
else
|
134
|
+
park_select(cli_input)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
class SwimScraper
|
6
|
+
|
7
|
+
attr_accessor :prop_id, :names, :location, :phone, :pools_type, :setting, :size, :accessible, :borough, :lat, :lon
|
8
|
+
@@swim = {}
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@prop_id = []
|
12
|
+
@names = []
|
13
|
+
@location = []
|
14
|
+
@phone = []
|
15
|
+
@pools_type = []
|
16
|
+
@setting = []
|
17
|
+
@size = []
|
18
|
+
@accessible = []
|
19
|
+
@lat = []
|
20
|
+
@lon = []
|
21
|
+
@borough = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def call
|
25
|
+
collect_and_create
|
26
|
+
end
|
27
|
+
|
28
|
+
def collect_and_create
|
29
|
+
xml = open("http://www.nycgovparks.org/bigapps/DPR_Pools_001.xml")
|
30
|
+
doc = Nokogiri::HTML(xml)
|
31
|
+
facilities = doc.xpath("//facility")
|
32
|
+
prop_id = facilities.xpath("//prop_id")
|
33
|
+
names = facilities.xpath("//name")
|
34
|
+
location = facilities.xpath("//location")
|
35
|
+
phone = facilities.xpath("//phone")
|
36
|
+
pools_type = facilities.xpath("//pools_type")
|
37
|
+
setting = facilities.xpath("//setting")
|
38
|
+
size = facilities.xpath("//size")
|
39
|
+
accessible = facilities.xpath("//accessible")
|
40
|
+
lat = facilities.xpath("//lat")
|
41
|
+
lon = facilities.xpath("//lon")
|
42
|
+
|
43
|
+
prop_id.each do |id|
|
44
|
+
@prop_id << id.text.to_s
|
45
|
+
@@swim[:prop_id] = @prop_id
|
46
|
+
end
|
47
|
+
|
48
|
+
names.each do |name|
|
49
|
+
@names << name.text.to_s
|
50
|
+
@@swim[:names] = @names
|
51
|
+
end
|
52
|
+
|
53
|
+
location.each do |location|
|
54
|
+
@location << location.text.to_s
|
55
|
+
@@swim[:location] = @location
|
56
|
+
end
|
57
|
+
|
58
|
+
phone.each do |phone|
|
59
|
+
@phone << phone.text.to_s
|
60
|
+
@@swim[:phone] = @phone
|
61
|
+
end
|
62
|
+
|
63
|
+
pools_type.each do |pools_type|
|
64
|
+
@pools_type << pools_type.text.to_s
|
65
|
+
@@swim[:pools_type] = @pools_type
|
66
|
+
end
|
67
|
+
|
68
|
+
setting.each do |setting|
|
69
|
+
@setting << setting.text.to_s
|
70
|
+
@@swim[:setting] = @setting
|
71
|
+
end
|
72
|
+
|
73
|
+
size.each do |size|
|
74
|
+
@size << size.text.to_s
|
75
|
+
@@swim[:size] = @size
|
76
|
+
end
|
77
|
+
|
78
|
+
accessible.each do |accessible|
|
79
|
+
@accessible << accessible.text.to_s
|
80
|
+
@@swim[:accessible] = @accessible
|
81
|
+
end
|
82
|
+
|
83
|
+
lat.each do |lat|
|
84
|
+
@lat << lat.text.to_s
|
85
|
+
@@swim[:lat] = @lat
|
86
|
+
end
|
87
|
+
|
88
|
+
lon.each do |lon|
|
89
|
+
@lon << lon.text.to_s
|
90
|
+
@@swim[:lon] = @lon
|
91
|
+
end
|
92
|
+
|
93
|
+
@@swim[:names].each do |name|
|
94
|
+
temp = Swim.new(name)
|
95
|
+
end
|
96
|
+
|
97
|
+
counter = 0
|
98
|
+
Swim.all.each do |instance|
|
99
|
+
instance.prop_id = @@swim[:prop_id][counter]
|
100
|
+
if instance.prop_id.start_with?("X")
|
101
|
+
instance.borough = "Bronx"
|
102
|
+
elsif instance.prop_id.start_with?("B")
|
103
|
+
instance.borough = "Brooklyn"
|
104
|
+
elsif instance.prop_id.start_with?("M")
|
105
|
+
instance.borough = "Manhattan"
|
106
|
+
elsif instance.prop_id.start_with?("Q")
|
107
|
+
instance.borough = "Queens"
|
108
|
+
elsif instance.prop_id.start_with?("R")
|
109
|
+
instance.borough = "Staten Island"
|
110
|
+
end
|
111
|
+
counter += 1
|
112
|
+
end
|
113
|
+
|
114
|
+
counter = 0
|
115
|
+
Swim.all.each do |instance|
|
116
|
+
instance.location = @@swim[:location][counter]
|
117
|
+
counter += 1
|
118
|
+
end
|
119
|
+
|
120
|
+
counter = 0
|
121
|
+
Swim.all.each do |instance|
|
122
|
+
instance.phone = @@swim[:phone][counter]
|
123
|
+
counter += 1
|
124
|
+
end
|
125
|
+
|
126
|
+
counter = 0
|
127
|
+
Swim.all.each do |instance|
|
128
|
+
instance.pools_type = @@swim[:pools_type][counter]
|
129
|
+
counter += 1
|
130
|
+
end
|
131
|
+
|
132
|
+
counter = 0
|
133
|
+
Swim.all.each do |instance|
|
134
|
+
instance.setting = @@swim[:setting][counter]
|
135
|
+
counter += 1
|
136
|
+
end
|
137
|
+
|
138
|
+
counter = 0
|
139
|
+
Swim.all.each do |instance|
|
140
|
+
instance.size = @@swim[:size][counter]
|
141
|
+
counter += 1
|
142
|
+
end
|
143
|
+
|
144
|
+
counter = 0
|
145
|
+
Swim.all.each do |instance|
|
146
|
+
instance.accessible = @@swim[:accessible][counter]
|
147
|
+
counter += 1
|
148
|
+
end
|
149
|
+
|
150
|
+
counter = 0
|
151
|
+
Swim.all.each do |instance|
|
152
|
+
instance.lat = @@swim[:lat][counter]
|
153
|
+
counter += 1
|
154
|
+
end
|
155
|
+
|
156
|
+
counter = 0
|
157
|
+
Swim.all.each do |instance|
|
158
|
+
instance.lon = @@swim[:lon][counter]
|
159
|
+
counter += 1
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
def all
|
165
|
+
@@swim
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'run-swim-hike-nyc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "run-swim-hike-nyc"
|
8
|
+
spec.version = RunSwimHike::VERSION
|
9
|
+
spec.authors = ["the-widget"]
|
10
|
+
spec.email = ["brennenawana108ny@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Discover places to Run, Swim or Hike in NYC!}
|
13
|
+
spec.homepage = "https://github.com/the-widget/run-swim-hike-nyc"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.executables = ["run-swim-hike"]
|
26
|
+
spec.require_paths = ["lib", "lib/run-swim-hike-nyc"]
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "nokogiri"
|
31
|
+
spec.add_development_dependency "open-uri"
|
32
|
+
spec.add_development_dependency "pry"
|
33
|
+
spec.add_development_dependency "rubygems"
|
34
|
+
spec.add_development_dependency "launchy"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: run-swim-hike-nyc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- the-widget
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: open-uri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubygems
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: launchy
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- brennenawana108ny@gmail.com
|
114
|
+
executables:
|
115
|
+
- run-swim-hike
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- CODE_OF_CONDUCT.md
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- NOTES.markdown
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/console
|
126
|
+
- bin/run-swim-hike
|
127
|
+
- bin/setup
|
128
|
+
- lib/run-swim-hike-nyc.rb
|
129
|
+
- lib/run-swim-hike-nyc/cli.rb
|
130
|
+
- lib/run-swim-hike-nyc/hike.rb
|
131
|
+
- lib/run-swim-hike-nyc/hike_scraper.rb
|
132
|
+
- lib/run-swim-hike-nyc/run.rb
|
133
|
+
- lib/run-swim-hike-nyc/run_scraper.rb
|
134
|
+
- lib/run-swim-hike-nyc/swim.rb
|
135
|
+
- lib/run-swim-hike-nyc/swim_scraper.rb
|
136
|
+
- lib/run-swim-hike-nyc/version.rb
|
137
|
+
- run-swim-hike-nyc.gemspec
|
138
|
+
homepage: https://github.com/the-widget/run-swim-hike-nyc
|
139
|
+
licenses:
|
140
|
+
- MIT
|
141
|
+
metadata:
|
142
|
+
allowed_push_host: https://rubygems.org
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
- lib/run-swim-hike-nyc
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.4.5.1
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Discover places to Run, Swim or Hike in NYC!
|
164
|
+
test_files: []
|