nsastorage 1.0.1 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/nsastorage/cli.rb +4 -3
- data/lib/nsastorage/crawl.rb +12 -8
- data/lib/nsastorage/facility.rb +2 -2
- data/lib/nsastorage/geocode.rb +4 -2
- data/lib/nsastorage/price.rb +4 -3
- data/lib/nsastorage/version.rb +1 -1
- metadata +6 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 949d27c50eb31c2fd300fb0b79746ce5582239ab7b471f82e69d8c7b39b45aa6
|
|
4
|
+
data.tar.gz: 3614b9d81dc60f5648ba04b36b499b04f30f3eb5b6208e28718bc5369b9be3be
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c28896e881cbed9602776cf811f77a3c09f7e461df19f3f5bd4fa2b6f3c3022bfcf449b12e07db0739db12ca0cf7944eabb77279efc0a2db60d0e3a74a8aecad
|
|
7
|
+
data.tar.gz: 63217a2e77acb61b0ad432298f6c428c795e385c6a7721a2551c88aabc13db8a06b1b07a482541c8bdbc85cfa933a875d5a74efe263b91cde839bb67f1056cb0
|
data/README.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
[](https://nsastorage.ksylvest.com)
|
|
7
7
|
[](https://circleci.com/gh/ksylvest/nsastorage)
|
|
8
8
|
|
|
9
|
+
A Ruby library offering both a CLI and API for scraping [NSA Storage](https://www.nsastorage.com/) self-storage facilities and prices.
|
|
10
|
+
|
|
9
11
|
## Installation
|
|
10
12
|
|
|
11
13
|
```bash
|
|
@@ -49,3 +51,7 @@ end
|
|
|
49
51
|
```bash
|
|
50
52
|
nsastorage crawl
|
|
51
53
|
```
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
nsastorage crawl "https://www.nsastorage.com/storage/georgia/storage-units-norcross/1-Western-Hills-Ct-2"
|
|
57
|
+
```
|
data/lib/nsastorage/cli.rb
CHANGED
|
@@ -21,7 +21,7 @@ module NSAStorage
|
|
|
21
21
|
command = argv.shift
|
|
22
22
|
|
|
23
23
|
case command
|
|
24
|
-
when 'crawl' then crawl
|
|
24
|
+
when 'crawl' then crawl(*argv)
|
|
25
25
|
else
|
|
26
26
|
warn("unsupported command=#{command.inspect}")
|
|
27
27
|
exit(Code::ERROR)
|
|
@@ -30,8 +30,9 @@ module NSAStorage
|
|
|
30
30
|
|
|
31
31
|
private
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
# @param url [String] optional
|
|
34
|
+
def crawl(url = nil)
|
|
35
|
+
Crawl.run(url:)
|
|
35
36
|
exit(Code::OK)
|
|
36
37
|
end
|
|
37
38
|
|
data/lib/nsastorage/crawl.rb
CHANGED
|
@@ -9,21 +9,25 @@ module NSAStorage
|
|
|
9
9
|
|
|
10
10
|
# @param stdout [IO] optional
|
|
11
11
|
# @param stderr [IO] optional
|
|
12
|
-
# @param
|
|
13
|
-
def initialize(stdout: $stdout, stderr: $stderr,
|
|
12
|
+
# @param url [String] optional
|
|
13
|
+
def initialize(stdout: $stdout, stderr: $stderr, url: nil)
|
|
14
14
|
@stdout = stdout
|
|
15
15
|
@stderr = stderr
|
|
16
|
-
@
|
|
16
|
+
@url = url
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def run
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
if @url
|
|
21
|
+
process(url: @url)
|
|
22
|
+
else
|
|
23
|
+
sitemap = Facility.sitemap
|
|
24
|
+
@stdout.puts("count=#{sitemap.links.count}")
|
|
25
|
+
@stdout.puts
|
|
26
|
+
sitemap.links.each { |link| process(url: link.loc) }
|
|
27
|
+
end
|
|
25
28
|
end
|
|
26
29
|
|
|
30
|
+
# @param url [String]
|
|
27
31
|
def process(url:)
|
|
28
32
|
@stdout.puts(url)
|
|
29
33
|
facility = Facility.fetch(url: url)
|
data/lib/nsastorage/facility.rb
CHANGED
|
@@ -37,7 +37,7 @@ module NSAStorage
|
|
|
37
37
|
attr_accessor :address
|
|
38
38
|
|
|
39
39
|
# @attribute [rw] geocode
|
|
40
|
-
# @return [Geocode]
|
|
40
|
+
# @return [Geocode, nil]
|
|
41
41
|
attr_accessor :geocode
|
|
42
42
|
|
|
43
43
|
# @attribute [rw] prices
|
|
@@ -127,7 +127,7 @@ module NSAStorage
|
|
|
127
127
|
|
|
128
128
|
# @return [String]
|
|
129
129
|
def text
|
|
130
|
-
"#{@id} | #{@name} | #{@phone} | #{@email} | #{@address.text} | #{@geocode.text}"
|
|
130
|
+
"#{@id} | #{@name} | #{@phone} | #{@email} | #{@address.text} | #{@geocode ? @geocode.text : 'N/A'}"
|
|
131
131
|
end
|
|
132
132
|
end
|
|
133
133
|
end
|
data/lib/nsastorage/geocode.rb
CHANGED
|
@@ -18,8 +18,10 @@ module NSAStorage
|
|
|
18
18
|
#
|
|
19
19
|
# @return [Geocode]
|
|
20
20
|
def self.parse(document:)
|
|
21
|
-
latitude = LATITUDE_REGEX.match(document.text)[:latitude
|
|
22
|
-
longitude = LONGITUDE_REGEX.match(document.text)[:longitude
|
|
21
|
+
latitude = LATITUDE_REGEX.match(document.text)&.[](:latitude)
|
|
22
|
+
longitude = LONGITUDE_REGEX.match(document.text)&.[](:longitude)
|
|
23
|
+
|
|
24
|
+
return if latitude.nil? || longitude.nil?
|
|
23
25
|
|
|
24
26
|
new(latitude: Float(latitude), longitude: Float(longitude))
|
|
25
27
|
end
|
data/lib/nsastorage/price.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module NSAStorage
|
|
4
4
|
# The price (id + dimensions + rate) for a facility.
|
|
5
5
|
class Price
|
|
6
|
-
ID_REGEX = %r{(?<
|
|
6
|
+
ID_REGEX = %r{/reservation/(?<facility_id>\d+)/(?<id>\d+)}
|
|
7
7
|
PRICE_SELECTOR = '[data-unit-size="small"],[data-unit-size="medium"],[data-unit-size="large"]'
|
|
8
8
|
|
|
9
9
|
# @attribute [rw] id
|
|
@@ -65,12 +65,13 @@ module NSAStorage
|
|
|
65
65
|
#
|
|
66
66
|
# @return [Price]
|
|
67
67
|
def self.parse(element:)
|
|
68
|
-
link = element.
|
|
68
|
+
link = element.at_css('.cta-holder > a[href*="reservation"]')
|
|
69
69
|
dimensions = Dimensions.parse(element:)
|
|
70
70
|
features = Features.parse(element:)
|
|
71
71
|
rates = Rates.parse(element:)
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
match = ID_REGEX.match(link['href']) if link
|
|
74
|
+
id = match ? match[:id] : "#{dimensions.id}-#{features.id}"
|
|
74
75
|
|
|
75
76
|
new(id:, dimensions:, features:, rates:)
|
|
76
77
|
end
|
data/lib/nsastorage/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nsastorage
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kevin Sylvestre
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: http
|
|
@@ -115,9 +114,9 @@ licenses:
|
|
|
115
114
|
metadata:
|
|
116
115
|
rubygems_mfa_required: 'true'
|
|
117
116
|
homepage_uri: https://github.com/ksylvest/nsastorage
|
|
118
|
-
source_code_uri: https://github.com/ksylvest/nsastorage
|
|
119
|
-
changelog_uri: https://github.com/ksylvest/nsastorage
|
|
120
|
-
|
|
117
|
+
source_code_uri: https://github.com/ksylvest/nsastorage/tree/v1.0.4
|
|
118
|
+
changelog_uri: https://github.com/ksylvest/nsastorage/releases/tag/v1.0.4
|
|
119
|
+
documentation_uri: https://nsastorage.ksylvest.com/
|
|
121
120
|
rdoc_options: []
|
|
122
121
|
require_paths:
|
|
123
122
|
- lib
|
|
@@ -132,8 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
132
131
|
- !ruby/object:Gem::Version
|
|
133
132
|
version: '0'
|
|
134
133
|
requirements: []
|
|
135
|
-
rubygems_version:
|
|
136
|
-
signing_key:
|
|
134
|
+
rubygems_version: 4.0.12
|
|
137
135
|
specification_version: 4
|
|
138
136
|
summary: A crawler for NSAStorage.
|
|
139
137
|
test_files: []
|