plant_info_scraper 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/plant-scraper-cli +3 -0
- data/bin/setup +8 -0
- data/lib/plant_info_scraper.rb +13 -0
- data/lib/plant_info_scraper/cli.rb +176 -0
- data/lib/plant_info_scraper/plant.rb +24 -0
- data/lib/plant_info_scraper/plant_filter.rb +8 -0
- data/lib/plant_info_scraper/scraper.rb +31 -0
- data/lib/plant_info_scraper/version.rb +3 -0
- data/plant_info_scraper.gemspec +43 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ff3f44ca1b370a832735df9e77a5a562f758c0f4ecbdd628128e4fca6540c217
|
4
|
+
data.tar.gz: 978d9d1bfcb896d44c6ce5fb999a4f3de8cdb3e3ad0649b04fad232619e3f31c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c7fb0347eafa5a60e71d6c4a13eb4eb247e8c7846750d40fdbd3ec5cef16e6125c87fa81cef1dca813c3ab13fd71d9596a9e391d627eb86a457b66869d0875fe
|
7
|
+
data.tar.gz: 29cb784b1fe844a7fafbcf59252d831a17cfded1cc7c099c0c9a2c88d343fbf90fe85edf9a056447951b42309a0329591d0fbd634a5c888546e4d2f8de352ab2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at eric@visiblycreative.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
plant_info_scraper (0.1.0)
|
5
|
+
colorize
|
6
|
+
nokogiri
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
coderay (1.1.2)
|
12
|
+
colorize (0.8.1)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
method_source (0.9.2)
|
15
|
+
mini_portile2 (2.3.0)
|
16
|
+
nokogiri (1.8.5)
|
17
|
+
mini_portile2 (~> 2.3.0)
|
18
|
+
pry (0.12.2)
|
19
|
+
coderay (~> 1.1.0)
|
20
|
+
method_source (~> 0.9.0)
|
21
|
+
rake (10.5.0)
|
22
|
+
rspec (3.8.0)
|
23
|
+
rspec-core (~> 3.8.0)
|
24
|
+
rspec-expectations (~> 3.8.0)
|
25
|
+
rspec-mocks (~> 3.8.0)
|
26
|
+
rspec-core (3.8.0)
|
27
|
+
rspec-support (~> 3.8.0)
|
28
|
+
rspec-expectations (3.8.2)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.8.0)
|
31
|
+
rspec-mocks (3.8.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.8.0)
|
34
|
+
rspec-support (3.8.0)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
bundler (~> 1.16)
|
41
|
+
plant_info_scraper!
|
42
|
+
pry
|
43
|
+
rake (~> 10.0)
|
44
|
+
rspec (~> 3.0)
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
1.16.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Eric Mayfield
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Development Notes
|
2
|
+
|
3
|
+
TODO: Pagination handling since only receiving 20 results at a time
|
4
|
+
|
5
|
+
|
6
|
+
# PlantInfoScraper
|
7
|
+
|
8
|
+
This Gem provides a CLI for a user to search and filter plants which grow well in their area via their zip code. The Gem uses Nokogiri to scrape data from the Better Homes and Gardens™ plant search to fuel the results.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'plant_info_scraper'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install plant_info_scraper
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
TODO: Write usage instructions here
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
33
|
+
|
34
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ericmayfield/plant_info_scraper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
43
|
+
|
44
|
+
## Code of Conduct
|
45
|
+
|
46
|
+
Everyone interacting in the PlantInfoScraper project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/plant_info_scraper/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "plant_info_scraper"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'pry'
|
4
|
+
require 'colorize'
|
5
|
+
|
6
|
+
require_relative "./plant_info_scraper/version"
|
7
|
+
require_relative "./plant_info_scraper/cli"
|
8
|
+
require_relative "./plant_info_scraper/scraper"
|
9
|
+
require_relative "./plant_info_scraper/plant"
|
10
|
+
|
11
|
+
# module PlantInfoScraper
|
12
|
+
# # Your code goes here...
|
13
|
+
# end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
class PlantScraper::CLI
|
2
|
+
|
3
|
+
def start
|
4
|
+
print "\n\n"
|
5
|
+
puts "Welcome to the Unofficial but Amazing Plant Scraper CLI!!!"
|
6
|
+
print "This Gem allows the user to search for plants which thrive in your region. Please enter your zip-code to continue: "
|
7
|
+
zip = zip_code?
|
8
|
+
|
9
|
+
print "\n\n"
|
10
|
+
print "If you would like to filter results by sunlight, height, or plant type enter \'" + "Y".green + "\' or " + "any key to continue.".green + ": "
|
11
|
+
if gets.chomp.capitalize == "Y"
|
12
|
+
print "\n\n"
|
13
|
+
sun_entry = sun_filter
|
14
|
+
height_entry = height_filter
|
15
|
+
plant_type_entry = plant_type_filter
|
16
|
+
PlantScraper::Scraper.scrape_zip_with_attributes(zip, sun_entry, height_entry, plant_type_entry)
|
17
|
+
elsif
|
18
|
+
PlantScraper::Scraper.scrape_by_zip(zip)
|
19
|
+
else
|
20
|
+
start
|
21
|
+
end
|
22
|
+
print "\n\n"
|
23
|
+
menu(zip)
|
24
|
+
print "\n\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
def zip_code?
|
28
|
+
zip = gets.chomp
|
29
|
+
|
30
|
+
if zip.length < 5 || zip.length > 5 || !/\A\d+\z/.match(zip)
|
31
|
+
print "Your Zip Code entry was incorrect. Please re-enter: "
|
32
|
+
zip_code?
|
33
|
+
else
|
34
|
+
puts zip.to_i
|
35
|
+
zip
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def menu(zip)
|
40
|
+
if PlantScraper::Plant.all.size > 0
|
41
|
+
puts " __".green
|
42
|
+
puts " _ / /|".green
|
43
|
+
puts " | \\\ \\/_/".green
|
44
|
+
puts " \\_\\| / __ ".green
|
45
|
+
puts " \\/_/__\\ ".green + ".-=='/~\\'".red
|
46
|
+
puts " ____,__/__,_____,______)".green + "/ /{~}}}".red
|
47
|
+
puts " -,------,----,-----,---,".green + "\\'-' {{~}}".red
|
48
|
+
puts " '-==.\\}/".red
|
49
|
+
print "\n\n"
|
50
|
+
puts "##############################-- PLANTS FOR #{zip} --##############################"
|
51
|
+
#binding.pry
|
52
|
+
PlantScraper::Plant.all.each.with_index(1) { |plant, i| puts "#{i}. #{plant.name.strip}"}
|
53
|
+
print "\n\n"
|
54
|
+
print "Enter the number of the plant to see its details: " #", #or \'" + "N".green + "\' "
|
55
|
+
input = gets.chomp
|
56
|
+
|
57
|
+
if input.to_i > PlantScraper::Plant.all.size
|
58
|
+
puts "Entry was incorrect press any key to try again".red
|
59
|
+
menu(zip) if gets.chomp
|
60
|
+
else
|
61
|
+
plant = PlantScraper::Plant.all[input.to_i-1]
|
62
|
+
print "\n\n"
|
63
|
+
puts "Plant Name: #{plant.name}"
|
64
|
+
puts "Light Type(s): #{plant.light}"
|
65
|
+
puts "Height Range: #{plant.height}"
|
66
|
+
puts "Growth Zones: #{plant.zones}"
|
67
|
+
puts "Plant Type(s): #{plant.type}"
|
68
|
+
puts "Summary: #{plant.summary}"
|
69
|
+
print "\n"
|
70
|
+
print "I hope you found this informative. To return to your results enter \'" + "R".green + "\', to start a new search enter \'" + "N".green + "\', or to exit enter \'" + "X".green + ": "
|
71
|
+
menu_input = gets.chomp.capitalize
|
72
|
+
|
73
|
+
#Case to Route user
|
74
|
+
case menu_input
|
75
|
+
when "R"
|
76
|
+
#Takes user back to original plants
|
77
|
+
puts "Now returning you to the plants list for zip-code #{zip}."
|
78
|
+
menu(zip)
|
79
|
+
when "N"
|
80
|
+
#Clears PlantScraper::Plant class array @@all and takes user back to new search
|
81
|
+
PlantScraper::Plant.clear
|
82
|
+
start
|
83
|
+
when "X"
|
84
|
+
#Ends program
|
85
|
+
exit
|
86
|
+
end
|
87
|
+
|
88
|
+
## ask for next 20 results
|
89
|
+
end
|
90
|
+
else
|
91
|
+
puts "You entered an incorrect zip code please enter a new zip code"
|
92
|
+
start
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def exit
|
97
|
+
puts "Thanks for using The Amazing but Unofficial Plant Scrapper!"
|
98
|
+
end
|
99
|
+
|
100
|
+
def sun_filter
|
101
|
+
print "For Sunlight, Enter \'" + "A".green + "\' for Any, \'" + "F".green + "\' for Full, \'" + "P".green + "\' for Partial, or \'" + "S".green + "\' for Shade. Only Choose One: "
|
102
|
+
sun_entry = gets.chomp.upcase
|
103
|
+
#checking that the sun filter is on a single digit and is only of 4 values filterable
|
104
|
+
if sun_entry.length > 1 || !(["A", "P", "F", "S"].include?(sun_entry))
|
105
|
+
puts "Your Entry was Incorrect Please Re-Enter Sun Type"
|
106
|
+
sun_filter
|
107
|
+
else
|
108
|
+
#Converting the sun filter to a URL appropriate value
|
109
|
+
case sun_entry
|
110
|
+
when "A"
|
111
|
+
sun_entry = ""
|
112
|
+
when "F"
|
113
|
+
sun_entry = "Sun"
|
114
|
+
when "P"
|
115
|
+
sun_entry = "Part+Sun"
|
116
|
+
when "S"
|
117
|
+
sun_entry = "Shade"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
sun_entry
|
122
|
+
end
|
123
|
+
|
124
|
+
def height_filter
|
125
|
+
print "For Height, Enter \'" + "A".green + "\' for Any, \'" + "XS".green + "\' for less than 6 inches, \'" + "SM".green + "\' for 6 - 12 inches, \'" + "MD".green + "\' for 1 - 3 feet , \'" + "LG".green + "\' for 3 - 8 feet, \'" + "XL".green + "\' for 8 - 20 feet, or \'" + "XXL".green + "\' for over 20 feet. Only choose One: "
|
126
|
+
height_entry = gets.chomp.upcase
|
127
|
+
#checking that the height filter is an appropriate entry and is only of 7 values filterable
|
128
|
+
if height_entry.length > 3 || !(["A", "XS", "SM", "MD", "LG", "XL", "XXL"].include?(height_entry))
|
129
|
+
puts height_entry
|
130
|
+
puts "Your Entry was Incorrect Please Re-Enter Sun Type"
|
131
|
+
height_filter
|
132
|
+
else
|
133
|
+
#Converting the height filter to a URL appropriate value
|
134
|
+
case height_entry
|
135
|
+
when "A"
|
136
|
+
height_entry = ""
|
137
|
+
when "XS"
|
138
|
+
height_entry = "0-6"
|
139
|
+
when "SM"
|
140
|
+
height_entry = "6-12"
|
141
|
+
when "MD"
|
142
|
+
height_entry = "1-3"
|
143
|
+
when "LG"
|
144
|
+
height_entry = "3-8"
|
145
|
+
when "XL"
|
146
|
+
height_entry = "8-20"
|
147
|
+
when "XXL"
|
148
|
+
height_entry = "20"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
height_entry
|
152
|
+
end
|
153
|
+
|
154
|
+
def plant_type_filter
|
155
|
+
print "For Plant Type, Enter \'" + "A".green + "\' for Any, \'" + "N".green + "\' for Annuals and \'" + "P".green + "\' for Perenials, only choose one Plant Type: "
|
156
|
+
plant_type_entry = gets.chomp.upcase
|
157
|
+
#checking that the sun filter is on a single digit and is only of 4 values filterable
|
158
|
+
if plant_type_entry.length > 1 || !(["A", "N", "P"].include?(plant_type_entry))
|
159
|
+
puts "Your Entry was Incorrect Please Re-Enter Plant Type"
|
160
|
+
plant_type_entry
|
161
|
+
else
|
162
|
+
#Converting the plant-type filter to a URL appropriate value
|
163
|
+
case plant_type_entry
|
164
|
+
when "A"
|
165
|
+
plant_type_entry = ""
|
166
|
+
when "N"
|
167
|
+
plant_type_entry = "Annual"
|
168
|
+
when "P"
|
169
|
+
plant_type_entry = "Perennial"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
plant_type_entry
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class PlantScraper::Plant
|
2
|
+
attr_accessor :name, :light, :zones, :height, :type, :summary
|
3
|
+
|
4
|
+
@@all = []
|
5
|
+
|
6
|
+
def initialize(name, light, height, zones, type, summary)
|
7
|
+
@name = name
|
8
|
+
@light = light
|
9
|
+
@height = height
|
10
|
+
@zones = zones
|
11
|
+
@type = type
|
12
|
+
@summary = summary
|
13
|
+
# TODO: Breakout scientific name in future @scientific_name = scientific_name
|
14
|
+
@@all << self
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.all
|
18
|
+
@@all
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.clear
|
22
|
+
@@all.clear
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class PlantScraper::Scraper
|
2
|
+
|
3
|
+
BASE_URL = "https://www.bhg.com/bin/plants/"
|
4
|
+
|
5
|
+
def self.scrape_by_zip(zip)
|
6
|
+
doc = Nokogiri::HTML(open(BASE_URL+"?zipZone=#{zip}")).css(".singleResult")
|
7
|
+
doc.each { |plant|
|
8
|
+
#array to store attributes while scraping
|
9
|
+
attributes = []
|
10
|
+
name = plant.css(".plantInfo .name h5 a").text
|
11
|
+
plant.css(".attributeSection .singleAttribute").each { |attribute| attributes << attribute.css(".value").text.delete("\n").strip.split.join(" ") }
|
12
|
+
summary = plant.css(".description p").text.strip
|
13
|
+
PlantScraper::Plant.new(name, attributes[0], attributes[1], attributes[2], attributes[3], summary )
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.scrape_zip_with_attributes(zip, sun_entry, height_entry, plant_type_entry)
|
18
|
+
attributes = "?zipZone=#{zip}&light=#{sun_entry}&height=#{height_entry}&type=#{plant_type_entry}"
|
19
|
+
|
20
|
+
doc = Nokogiri::HTML(open(BASE_URL+attributes)).css(".singleResult")
|
21
|
+
doc.each { |plant|
|
22
|
+
#array to store attributes while scraping
|
23
|
+
attributes = []
|
24
|
+
name = plant.css(".plantInfo .name h5 a").text
|
25
|
+
plant.css(".attributeSection .singleAttribute").each { |attribute| attributes << attribute.css(".value").text.delete("\n").strip.split.join(" ") }
|
26
|
+
summary = plant.css(".description p").text.strip
|
27
|
+
PlantScraper::Plant.new(name, attributes[0], attributes[1], attributes[2], attributes[3], summary )
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "plant_info_scraper/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "plant_info_scraper"
|
8
|
+
spec.version = PlantScraper::VERSION
|
9
|
+
spec.authors = ["Eric Mayfield"]
|
10
|
+
spec.email = ["eric@visiblycreative.com"]
|
11
|
+
|
12
|
+
spec.summary = "Gem to search plants by zip code which grow well in a user's area."
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
16
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
17
|
+
# if spec.respond_to?(:metadata)
|
18
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
19
|
+
|
20
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
21
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
22
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
23
|
+
# else
|
24
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
25
|
+
# "public gem pushes."
|
26
|
+
# end
|
27
|
+
|
28
|
+
# Specify which files should be added to the gem when it is released.
|
29
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
30
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
31
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
|
+
end
|
33
|
+
spec.bindir = "exe"
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
+
spec.require_paths = ["lib"]
|
36
|
+
|
37
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
38
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
39
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
40
|
+
spec.add_development_dependency "pry"
|
41
|
+
spec.add_dependency "nokogiri"
|
42
|
+
spec.add_dependency "colorize"
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: plant_info_scraper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Mayfield
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
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: nokogiri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
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: colorize
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- eric@visiblycreative.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/plant-scraper-cli
|
115
|
+
- bin/setup
|
116
|
+
- lib/plant_info_scraper.rb
|
117
|
+
- lib/plant_info_scraper/cli.rb
|
118
|
+
- lib/plant_info_scraper/plant.rb
|
119
|
+
- lib/plant_info_scraper/plant_filter.rb
|
120
|
+
- lib/plant_info_scraper/scraper.rb
|
121
|
+
- lib/plant_info_scraper/version.rb
|
122
|
+
- plant_info_scraper.gemspec
|
123
|
+
homepage:
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.7.8
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Gem to search plants by zip code which grow well in a user's area.
|
147
|
+
test_files: []
|