museum_day 0.1.1 → 0.1.2
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/.DS_Store +0 -0
- data/Gemfile.lock +1 -1
- data/README.md +0 -12
- data/lib/museum_day/cli.rb +49 -53
- data/lib/museum_day/museum.rb +5 -46
- data/lib/museum_day/scraper.rb +23 -1
- data/lib/museum_day/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d938321beef4fed01f48eeec3bf71810e44a6d985bf19016e5431c4a4b20f43b
|
|
4
|
+
data.tar.gz: e3eb4b10c9d9ca4f22f0aafdff50f643fda270b130c90cca12586dd21e3664fa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac309afc924b9b76d27d71275bd8fa68704cc4ccbed3383d6cf8417df87d71d6a3cfbf9fb0d1b99c76ea6faf7124b7673b68177fcb4a37a95e879f136bebf63b
|
|
7
|
+
data.tar.gz: cb95c512b1483d69fffa9ce58936fd045f97a12bd38451dc8f1131b51a886183172f3a69511826e9aefeeb4f175b84c50e5986a6a77814c9d77d9d7110f7a9aa
|
data/.DS_Store
ADDED
|
Binary file
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -4,18 +4,6 @@ This Ruby Gem provides a CLI to view the participating Museums for Museum Day ti
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
Add this line to your application's Gemfile:
|
|
8
|
-
|
|
9
|
-
```ruby
|
|
10
|
-
gem 'museum_day'
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
And then execute:
|
|
14
|
-
|
|
15
|
-
$ bundle install
|
|
16
|
-
|
|
17
|
-
Or install it yourself as:
|
|
18
|
-
|
|
19
7
|
$ gem install museum_day
|
|
20
8
|
|
|
21
9
|
## Usage
|
data/lib/museum_day/cli.rb
CHANGED
|
@@ -8,50 +8,30 @@ class MuseumDay::CLI
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def start
|
|
11
|
-
if !zipcode
|
|
12
|
-
get_zipcode
|
|
13
|
-
end
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
list_museums(zipcode)
|
|
12
|
+
get_zipcode if !zipcode
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
while !input.to_i.between?(1, MuseumDay::Museum.all.size)
|
|
21
|
-
puts ""
|
|
22
|
-
puts "Enter the number of the museum you'd like more info on or type exit"
|
|
23
|
-
input = gets.strip
|
|
14
|
+
exit?(zipcode)
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
if input.to_i.between?(1, MuseumDay::Museum.all.size)
|
|
27
|
-
print_museum_details(input)
|
|
28
|
-
else
|
|
29
|
-
puts "Invalid number"
|
|
16
|
+
list_museums(zipcode)
|
|
30
17
|
|
|
31
|
-
|
|
32
|
-
end
|
|
18
|
+
get_user_input_for_details_and_print
|
|
33
19
|
|
|
34
20
|
menu
|
|
35
21
|
|
|
36
22
|
input = gets.strip.downcase
|
|
37
23
|
exit?(input)
|
|
38
24
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
@zipcode = nil
|
|
42
|
-
start
|
|
43
|
-
elsif input == "back"
|
|
44
|
-
MuseumDay::Museum.clear_all
|
|
45
|
-
start
|
|
46
|
-
end
|
|
25
|
+
new_or_back?(input)
|
|
26
|
+
|
|
47
27
|
end
|
|
48
28
|
|
|
49
29
|
def list_museums(input)
|
|
50
30
|
|
|
51
|
-
MuseumDay::Scraper.new(input)
|
|
31
|
+
@scraper = MuseumDay::Scraper.new(input)
|
|
32
|
+
@scraper.make_museums
|
|
52
33
|
|
|
53
|
-
puts ""
|
|
54
|
-
puts "--------------Listing museums near #{zipcode}--------------"
|
|
34
|
+
puts "\n--------------Listing museums near #{zipcode}--------------"
|
|
55
35
|
|
|
56
36
|
MuseumDay::Museum.all.each.with_index(1) do |museum, idx|
|
|
57
37
|
puts "#{idx}. #{museum.name} - #{museum.city}"
|
|
@@ -62,55 +42,71 @@ class MuseumDay::CLI
|
|
|
62
42
|
|
|
63
43
|
museum = MuseumDay::Museum.find(input.to_i)
|
|
64
44
|
|
|
65
|
-
|
|
66
|
-
|
|
45
|
+
@scraper.scrape_details(museum)
|
|
46
|
+
|
|
47
|
+
puts "\n--------------#{museum.name}--------------"
|
|
67
48
|
puts "#{museum.address}"
|
|
68
49
|
puts " Hours: #{museum.hours}"
|
|
69
|
-
puts ""
|
|
70
|
-
puts "Phone Number: #{museum.phone_number}"
|
|
50
|
+
puts "\nPhone Number: #{museum.phone_number}"
|
|
71
51
|
puts "Website: #{museum.website_url}"
|
|
52
|
+
puts "Facebook: #{museum.fb}" if museum.fb
|
|
53
|
+
puts "Twitter: #{museum.twitter}" if museum.twitter
|
|
54
|
+
puts "\n--------------Description--------------"
|
|
55
|
+
puts "#{museum.description}"
|
|
56
|
+
end
|
|
72
57
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
puts "Facebook: #{museum.fb}"
|
|
76
|
-
end
|
|
58
|
+
def get_user_input_for_details_and_print
|
|
59
|
+
input = 0
|
|
77
60
|
|
|
78
|
-
|
|
79
|
-
puts "
|
|
80
|
-
|
|
61
|
+
while !input.to_i.between?(1, MuseumDay::Museum.all.size)
|
|
62
|
+
puts "\nEnter the number of the museum you'd like more info on or type exit"
|
|
63
|
+
input = gets.strip
|
|
81
64
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
65
|
+
exit?(input)
|
|
66
|
+
if input.to_i.between?(1, MuseumDay::Museum.all.size)
|
|
67
|
+
print_museum_details(input)
|
|
68
|
+
else
|
|
69
|
+
puts "Invalid number"
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
end
|
|
85
73
|
end
|
|
86
74
|
|
|
87
75
|
def menu
|
|
88
|
-
puts ""
|
|
89
|
-
puts "To go back to list of
|
|
76
|
+
puts "\n---------------------------------------------"
|
|
77
|
+
puts "To go back to list of museums, enter 'back'."
|
|
90
78
|
puts "To search a new zipcode, enter 'new'."
|
|
91
79
|
puts "To quit, enter 'exit'."
|
|
80
|
+
puts "---------------------------------------------"
|
|
92
81
|
end
|
|
93
82
|
|
|
94
83
|
def get_zipcode
|
|
95
|
-
puts ""
|
|
96
|
-
puts "Please enter your zipcode or type exit"
|
|
84
|
+
puts "\nPlease enter your zipcode or type exit"
|
|
97
85
|
|
|
98
|
-
|
|
86
|
+
self.zipcode = gets.strip
|
|
99
87
|
exit?(zipcode)
|
|
100
88
|
|
|
101
89
|
if zipcode.size != 5
|
|
102
|
-
puts ""
|
|
103
|
-
puts "Invalid Zipcode"
|
|
90
|
+
puts "\nInvalid Zipcode"
|
|
104
91
|
get_zipcode
|
|
105
92
|
end
|
|
106
93
|
end
|
|
107
94
|
|
|
108
|
-
def
|
|
109
|
-
if input
|
|
110
|
-
|
|
95
|
+
def new_or_back?(input)
|
|
96
|
+
if input == "new"
|
|
97
|
+
MuseumDay::Museum.clear_all
|
|
98
|
+
self.zipcode = nil
|
|
99
|
+
start
|
|
100
|
+
elsif input == "back"
|
|
101
|
+
MuseumDay::Museum.clear_all
|
|
102
|
+
start
|
|
111
103
|
end
|
|
112
104
|
end
|
|
113
105
|
|
|
106
|
+
def exit?(input)
|
|
107
|
+
goodbye if input.downcase == "exit"
|
|
108
|
+
end
|
|
109
|
+
|
|
114
110
|
def goodbye
|
|
115
111
|
puts "-----------------"
|
|
116
112
|
puts "| Goodbye |"
|
data/lib/museum_day/museum.rb
CHANGED
|
@@ -5,20 +5,11 @@ class MuseumDay::Museum
|
|
|
5
5
|
|
|
6
6
|
@@all = []
|
|
7
7
|
|
|
8
|
-
def
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
museum.at("div strong").next_sibling.text.strip
|
|
14
|
-
)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def initialize(name = nil, city = nil, url = nil, hours = nil)
|
|
18
|
-
@name = name
|
|
19
|
-
@city = city
|
|
20
|
-
@url = url
|
|
21
|
-
@hours = hours
|
|
8
|
+
def initialize(attributes)
|
|
9
|
+
@name = attributes[:name]
|
|
10
|
+
@city = attributes[:city]
|
|
11
|
+
@url = attributes[:url]
|
|
12
|
+
@hours = attributes[:hours]
|
|
22
13
|
@@all << self
|
|
23
14
|
end
|
|
24
15
|
|
|
@@ -30,38 +21,6 @@ class MuseumDay::Museum
|
|
|
30
21
|
self.all[id-1]
|
|
31
22
|
end
|
|
32
23
|
|
|
33
|
-
def address
|
|
34
|
-
@address ||= doc.css("p.address").text.strip
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def phone_number
|
|
38
|
-
@phone_number ||= doc.at("i.fa-phone").next_sibling.text.strip
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def website_url
|
|
42
|
-
@website_url ||= doc.css("i.fa-external-link + a").attribute("href").value
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def social_urls
|
|
46
|
-
social_links = doc.css("div.contact a").collect { |link| link.attribute("href").value }
|
|
47
|
-
|
|
48
|
-
social_links.each do |link|
|
|
49
|
-
if link.include?("twitter")
|
|
50
|
-
self.twitter = link
|
|
51
|
-
elsif link.include?("facebook")
|
|
52
|
-
self.fb = link
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def description
|
|
58
|
-
@description ||= doc.css("div.aux-info p").first.text
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def doc
|
|
62
|
-
@doc ||= Nokogiri::HTML(open("https://www.smithsonianmag.com#{self.url}"))
|
|
63
|
-
end
|
|
64
|
-
|
|
65
24
|
def self.clear_all
|
|
66
25
|
@@all.clear
|
|
67
26
|
end
|
data/lib/museum_day/scraper.rb
CHANGED
|
@@ -16,8 +16,30 @@ class MuseumDay::Scraper
|
|
|
16
16
|
|
|
17
17
|
def make_museums
|
|
18
18
|
scrape_museums_index.each do |museum|
|
|
19
|
-
|
|
19
|
+
attribute_hash = {
|
|
20
|
+
name: museum.css("h4.name").text,
|
|
21
|
+
city: museum.css("h5.location").text,
|
|
22
|
+
url: museum.css("a").attribute("href").value,
|
|
23
|
+
hours: museum.at("div strong").next_sibling.text.strip
|
|
24
|
+
}
|
|
25
|
+
MuseumDay::Museum.new(attribute_hash)
|
|
20
26
|
end
|
|
21
27
|
end
|
|
22
28
|
|
|
29
|
+
def scrape_details(museum)
|
|
30
|
+
doc = Nokogiri::HTML(open("https://www.smithsonianmag.com#{museum.url}"))
|
|
31
|
+
museum.description = doc.css("div.aux-info p").first.text
|
|
32
|
+
museum.address = doc.css("p.address").text.strip
|
|
33
|
+
museum.website_url = doc.css("i.fa-external-link + a").attribute("href").value
|
|
34
|
+
museum.phone_number = doc.at("i.fa-phone").next_sibling.text.strip
|
|
35
|
+
|
|
36
|
+
#Scrape Socials
|
|
37
|
+
doc.css("div.contact a").collect { |link| link.attribute("href").value }.each do |link|
|
|
38
|
+
if link.include?("twitter")
|
|
39
|
+
museum.twitter = link
|
|
40
|
+
elsif link.include?("facebook")
|
|
41
|
+
museum.fb = link
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
23
45
|
end
|
data/lib/museum_day/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: museum_day
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Darrel Castellano
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-10-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -75,6 +75,7 @@ executables:
|
|
|
75
75
|
extensions: []
|
|
76
76
|
extra_rdoc_files: []
|
|
77
77
|
files:
|
|
78
|
+
- ".DS_Store"
|
|
78
79
|
- ".gitignore"
|
|
79
80
|
- CODE_OF_CONDUCT.md
|
|
80
81
|
- Gemfile
|