apartmenthunter 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 +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +33 -0
- data/Rakefile +6 -0
- data/apartmenthunter.gemspec +41 -0
- data/bin/apartmenthunter +8 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/apartmenthunter.rb +22 -0
- data/lib/apartmenthunter/area.rb +21 -0
- data/lib/apartmenthunter/cli.rb +89 -0
- data/lib/apartmenthunter/export.rb +18 -0
- data/lib/apartmenthunter/scraper-inprog.rb +87 -0
- data/lib/apartmenthunter/scraper.rb +92 -0
- data/lib/apartmenthunter/test.rb +13 -0
- data/lib/apartmenthunter/version.rb +3 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f047bc5f91e010417fa167c5f32d063ae8f8d3f7
|
4
|
+
data.tar.gz: 770b312f9fa09fbf6a666e4a2cc2d8d2fa2dafea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e8d39f7bac862bc5d9274f75488d516448289ae36d6110100a7329dfcbb8ca7fcf20ea61167a791615f52a9217f5d5a670d6c41820426d84a7d5dfa6a20bbd7a
|
7
|
+
data.tar.gz: a9845cab8125179b05a27847643a9a6f571f90030b07607c644f9578792a937803fab584511a4db780fdd01f0fd110d58ed73a6bce9ac166a799bd963c759c8d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at driley3@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 danielriley06
|
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,33 @@
|
|
1
|
+
# Apartment Hunter
|
2
|
+
|
3
|
+
Welcome to Apartment Hunter! This gem will search Craigslist for apartments in the Greater New York area.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
$ gem install apartmenthunter'
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Type the following into your terminal:
|
14
|
+
```
|
15
|
+
$ apartmenthunter
|
16
|
+
```
|
17
|
+
|
18
|
+
The CLI will walk you through it's usage. First you must select a specific area in or around the city, or select all areas. Then enter the requested parameters to narrow down your search. The results will be displayed, which you will have the option to export to CSV.
|
19
|
+
|
20
|
+
## Development
|
21
|
+
|
22
|
+
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.
|
23
|
+
|
24
|
+
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).
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/apartmenthunter. 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.
|
29
|
+
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'apartmenthunter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "apartmenthunter"
|
8
|
+
spec.version = Apartmenthunter::VERSION
|
9
|
+
spec.authors = ["danielriley06"]
|
10
|
+
spec.email = ["driley3@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{CLI based scraper to find apartments in the NYC area.}
|
13
|
+
spec.description = %q{CLI based scraper to find apartments in the NYC area. Based on several parameters such as min/max price, number of bedrooms/bathrooms, etc.}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
#if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
#else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
#end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency 'formatador'
|
31
|
+
spec.add_dependency 'ruby-progressbar'
|
32
|
+
spec.add_dependency 'highline'
|
33
|
+
spec.add_dependency 'colorize'
|
34
|
+
spec.add_dependency 'mechanize'
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
39
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
+
end
|
data/bin/apartmenthunter
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "apartmenthunter"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'apartmenthunter/cli'
|
2
|
+
require 'apartmenthunter/scraper'
|
3
|
+
|
4
|
+
module Apartmenthunter
|
5
|
+
class Run
|
6
|
+
attr_reader :cli
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@cli = CLI.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
cli.welcome
|
14
|
+
cli.locate
|
15
|
+
cli.parameters
|
16
|
+
cli.results
|
17
|
+
cli.display_results
|
18
|
+
cli.post_search_options
|
19
|
+
cli.goodbye
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'apartmenthunter/cli'
|
2
|
+
require 'apartmenthunter/scraper'
|
3
|
+
|
4
|
+
module Apartmenthunter
|
5
|
+
class Area
|
6
|
+
attr_reader :area
|
7
|
+
|
8
|
+
@@all = ""
|
9
|
+
|
10
|
+
def initialize(area)
|
11
|
+
@@area = area
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.set_area
|
16
|
+
areas = {"All of the Greater New York area" => "", "New Jersey" => "/jsy", "Bronx" => "/brx", "Brooklyn" => "/brk", "Fairfield" => "/fct", "Long Island" => "/lgi", "Manhattan" => "/mnh", "Queens" => "/que", "Staten Island" =>"/stn", "Westchester" => "/wch"}
|
17
|
+
return areas[@@area]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'apartmenthunter/scraper'
|
2
|
+
require 'apartmenthunter/area'
|
3
|
+
require 'apartmenthunter/export'
|
4
|
+
require 'apartmenthunter'
|
5
|
+
require 'formatador'
|
6
|
+
require 'highline/import'
|
7
|
+
require 'colorize'
|
8
|
+
|
9
|
+
|
10
|
+
module Apartmenthunter
|
11
|
+
class Apartmenthunter::CLI
|
12
|
+
attr_accessor :area, :min_price, :max_price, :bedrooms, :bathrooms, :zip, :miles, :results
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
def welcome
|
17
|
+
puts %q[
|
18
|
+
_ _ _ _ _ _
|
19
|
+
/_\ _ __ __ _ _ _| |_ _ __ ___ _ _| |_ | || |_ _ _ _| |_ ___ _ _
|
20
|
+
/ _ \| '_ \/ _` | '_| _| ' \/ -_) ' \ _| | __ | || | ' \ _/ -_) '_|
|
21
|
+
/_/ \_\ .__/\__,_|_| \__|_|_|_\___|_||_\__| |_||_|\_,_|_||_\__\___|_|
|
22
|
+
|_| ].green.bold
|
23
|
+
puts "\nThis handy gem will help you find apartments availible for rent on Craigslist in the Greater New York area.\n".green.bold
|
24
|
+
end
|
25
|
+
|
26
|
+
def locate
|
27
|
+
@locations = ["All of the Greater New York area", "New Jersey", "Bronx", "Brooklyn", "Fairfield", "Long Island", "Manhattan", "Queens", "Staten Island", "Westchester", "Exit"]
|
28
|
+
choose do |menu|
|
29
|
+
menu.layout = :list
|
30
|
+
menu.prompt = "\nPlease enter your the specific area you would like to search : ".green
|
31
|
+
menu.choices(*@locations) {|command| command == "Exit" ? goodbye : current_area = Area.new(command)}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def parameters
|
36
|
+
say("\nPlease begin by answering a few questions to narrow down your search.".red)
|
37
|
+
@min_price = ask("What is the minimum amount of rent you would like to pay? ", lambda { |p| p.sub(/[^0-9A-Za-z]/, '')})
|
38
|
+
@max_price = ask("What is the maximum amount of rent you would like to pay? ", lambda { |p| p.sub(/[^0-9A-Za-z]/, '')})
|
39
|
+
@bedrooms = ask("Please enter the number of bedrooms (between 1 and 8): ", Integer) { |q| q.in = 0..8 }
|
40
|
+
@bathrooms = ask("Please enter the number of bathrooms (between 1 and 8): ", Integer) { |q| q.in = 0..8 }
|
41
|
+
@zip = ask("Please enter the 5 digit zip code you would like to center your search around : ", String) do |q|
|
42
|
+
q.validate = /\A\d{5}(?:-?\d{4})?\Z/
|
43
|
+
q.responses[:not_valid] = "Please enter a 5 digit zip code."
|
44
|
+
end
|
45
|
+
@miles = ask("Finally, please enter the number of miles (between 0 and 500) you would like to search from that zip code : ", Integer) { |q| q.in = 0..500 }
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def results
|
50
|
+
results = Scraper.new(@min_price, @max_price, @bedrooms, @bathrooms, @zip, @miles)
|
51
|
+
@apt_results = results.results
|
52
|
+
end
|
53
|
+
|
54
|
+
def display_results
|
55
|
+
Formatador.display_compact_table(@apt_results)
|
56
|
+
end
|
57
|
+
|
58
|
+
def post_search_options
|
59
|
+
say("\nPlease select wether you would like to export these results, restart your search, or quit : \n".green)
|
60
|
+
loop do
|
61
|
+
choose do |menu|
|
62
|
+
menu.layout = :list
|
63
|
+
menu.choice("Export Results") do |command|
|
64
|
+
csv_export
|
65
|
+
end
|
66
|
+
menu.choice("Restart Search") do |command|
|
67
|
+
Apartmenthunter::Run.new.call
|
68
|
+
end
|
69
|
+
menu.choice("Exit") do |command|
|
70
|
+
goodbye
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def csv_export
|
77
|
+
Export.output(@apt_results)
|
78
|
+
say("\nYour results are located in the file aptsearchresults.csv your Documents folder")
|
79
|
+
post_search_options
|
80
|
+
end
|
81
|
+
|
82
|
+
def goodbye
|
83
|
+
puts "\nHappy apartment hunting!\n"
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'apartmenthunter/cli'
|
3
|
+
|
4
|
+
module Apartmenthunter
|
5
|
+
class Export
|
6
|
+
def self.output(results)
|
7
|
+
hashes = results
|
8
|
+
column_names = hashes.first.keys
|
9
|
+
s = CSV.generate do |csv|
|
10
|
+
csv << column_names
|
11
|
+
hashes.each do |x|
|
12
|
+
csv << x.values
|
13
|
+
end
|
14
|
+
end
|
15
|
+
File.write("#{Dir.home}/Documents/aptsearchresults.csv", s)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
require 'ruby-progressbar'
|
3
|
+
require 'apartmenthunter/cli'
|
4
|
+
require 'apartmenthunter/area'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
module Apartmenthunter
|
8
|
+
class Scraper
|
9
|
+
attr_accessor :area, :min_price, :max_price, :bedrooms, :bathrooms, :miles, :zip, :results, :page, :result_page, :scraper, :set_address, :scrape, :form_mechanize, :get_results
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
def initialize(min_price, max_price, bedrooms, bathrooms, zip, miles)
|
14
|
+
@area = Area.set_area
|
15
|
+
@min_price = min_price
|
16
|
+
@max_price = max_price
|
17
|
+
@bedrooms = bedrooms
|
18
|
+
@bathrooms = bathrooms
|
19
|
+
@zip = zip
|
20
|
+
@miles = miles
|
21
|
+
@results = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
# Instantiate a new web scraper with Mechanize
|
26
|
+
@scraper = Mechanize.new
|
27
|
+
|
28
|
+
# Mechanize setup to rate limit your scraping
|
29
|
+
# to prevent IP ban.
|
30
|
+
@scraper.history_added = Proc.new { sleep 0.5 }
|
31
|
+
set_address
|
32
|
+
scrape
|
33
|
+
form_mechanize
|
34
|
+
get_results
|
35
|
+
return @results
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.set_address
|
39
|
+
# Set the address for the area to be searched set by area method in CLI
|
40
|
+
#@area = "/jsy"
|
41
|
+
area = @area
|
42
|
+
@address = "http://newyork.craigslist.org/search"+"#{area}"+"/aap"
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.scrape
|
46
|
+
#Let us scrape.
|
47
|
+
@page = @scraper.get(@address)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.form_mechanize
|
51
|
+
# Use Mechanize to enter search terms into the form fields desired. (Second form on page)
|
52
|
+
form = @page.forms[1]
|
53
|
+
|
54
|
+
form['min_price'] = @min_price
|
55
|
+
form['max_price'] = @max_price
|
56
|
+
form['bedrooms'] = @bedrooms
|
57
|
+
form['bathrooms'] = @bathrooms
|
58
|
+
form['search_distance'] = @miles
|
59
|
+
form['postal'] = @zip
|
60
|
+
|
61
|
+
@result_page = form.submit
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.get_results
|
65
|
+
raw_results = @result_page.search('p.row')
|
66
|
+
|
67
|
+
raw_results.each do |result|
|
68
|
+
apt_hash = {:location => "", :name => "", :price => "", :url => ""}
|
69
|
+
link = result.css('a')[1]
|
70
|
+
apt_hash[:name] = link.text.strip
|
71
|
+
apt_hash[:url] = "http://newyork.craigslist.org" + link.attributes["href"].value
|
72
|
+
apt_hash[:price] = result.search('span.price').text
|
73
|
+
apt_hash[:location] = result.search('span.pnr').text[3..-13]
|
74
|
+
# Save results
|
75
|
+
@results << apt_hash
|
76
|
+
end
|
77
|
+
|
78
|
+
progress = ProgressBar.create(:title => "Downloading", :total => 20, :length => 40)
|
79
|
+
20.times do
|
80
|
+
sleep 0.1
|
81
|
+
progress.increment
|
82
|
+
end
|
83
|
+
puts @results
|
84
|
+
binding.pry
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
require 'ruby-progressbar'
|
3
|
+
require 'apartmenthunter/cli'
|
4
|
+
require 'apartmenthunter/area'
|
5
|
+
|
6
|
+
|
7
|
+
module Apartmenthunter
|
8
|
+
class Scraper
|
9
|
+
attr_accessor :results
|
10
|
+
attr_reader :area, :min_price, :max_price, :bedrooms, :bathrooms, :zip, :miles
|
11
|
+
|
12
|
+
@@all = []
|
13
|
+
|
14
|
+
def initialize(min_price, max_price, bedrooms, bathrooms, zip, miles)
|
15
|
+
@area = Area.set_area
|
16
|
+
@min_price = min_price
|
17
|
+
@max_price = max_price
|
18
|
+
@bedrooms = bedrooms
|
19
|
+
@bathrooms = bathrooms
|
20
|
+
@zip = zip
|
21
|
+
@miles = miles
|
22
|
+
@results = []
|
23
|
+
@@all << self
|
24
|
+
self.mechanize
|
25
|
+
end
|
26
|
+
|
27
|
+
def mechanize
|
28
|
+
# Instantiate a new web scraper with Mechanize
|
29
|
+
@scraper = Mechanize.new
|
30
|
+
|
31
|
+
# Mechanize setup to rate limit your scraping
|
32
|
+
# to prevent IP ban.
|
33
|
+
@scraper.history_added = Proc.new { sleep 0.5 }
|
34
|
+
self.set_address
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_address
|
38
|
+
# Set the address for the area to be searched set by area method in CLI
|
39
|
+
#@area = "/jsy"
|
40
|
+
area = @area
|
41
|
+
@address = "http://newyork.craigslist.org/search"+"#{area}"+"/aap"
|
42
|
+
self.scrape_craig
|
43
|
+
end
|
44
|
+
|
45
|
+
def scrape_craig
|
46
|
+
#Let us scrape.
|
47
|
+
@page = @scraper.get(@address)
|
48
|
+
|
49
|
+
# Use Mechanize to enter search terms into the form fields desired. (Second form on page)
|
50
|
+
form = @page.forms[1]
|
51
|
+
|
52
|
+
form['min_price'] = @min_price
|
53
|
+
form['max_price'] = @max_price
|
54
|
+
form['bedrooms'] = @bedrooms
|
55
|
+
form['bathrooms'] = @bathrooms
|
56
|
+
form['search_distance'] = @miles
|
57
|
+
form['postal'] = @zip
|
58
|
+
|
59
|
+
@result_page = form.submit
|
60
|
+
self.parse_results
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_results
|
64
|
+
raw_results = @result_page.search('p.row')
|
65
|
+
|
66
|
+
raw_results.each do |result|
|
67
|
+
apt_hash = {:location => "", :name => "", :price => "", :url => ""}
|
68
|
+
link = result.css('a')[1]
|
69
|
+
apt_hash[:name] = link.text.strip
|
70
|
+
apt_hash[:url] = "http://newyork.craigslist.org" + link.attributes["href"].value
|
71
|
+
apt_hash[:price] = result.search('span.price').text
|
72
|
+
apt_hash[:location] = result.search('span.pnr').text[3..-13]
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
# Save results
|
77
|
+
@results << apt_hash
|
78
|
+
end
|
79
|
+
self.progress
|
80
|
+
end
|
81
|
+
|
82
|
+
def progress
|
83
|
+
progress = ProgressBar.create(:title => "Downloading", :total => 20, :length => 40)
|
84
|
+
20.times do
|
85
|
+
sleep 0.1
|
86
|
+
progress.increment
|
87
|
+
end
|
88
|
+
|
89
|
+
return @results
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'highline/import'
|
2
|
+
|
3
|
+
def test
|
4
|
+
@allArchiveDirs = ["deletemetest", "old2", "old3", "old4", "TestData", "testy123", "tsty"]
|
5
|
+
choose do |menu|
|
6
|
+
menu.prompt = 'Please choose a project to access:'
|
7
|
+
menu.choices(*@allArchiveDirs) do |chosen|
|
8
|
+
puts "Item chosen: #{chosen}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
test
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apartmenthunter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- danielriley06
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: formatador
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-progressbar
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: highline
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
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: colorize
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
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: mechanize
|
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: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.12'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.12'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.0'
|
125
|
+
description: CLI based scraper to find apartments in the NYC area. Based on several
|
126
|
+
parameters such as min/max price, number of bedrooms/bathrooms, etc.
|
127
|
+
email:
|
128
|
+
- driley3@gmail.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".travis.yml"
|
136
|
+
- CODE_OF_CONDUCT.md
|
137
|
+
- Gemfile
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- apartmenthunter.gemspec
|
142
|
+
- bin/apartmenthunter
|
143
|
+
- bin/console
|
144
|
+
- bin/setup
|
145
|
+
- lib/apartmenthunter.rb
|
146
|
+
- lib/apartmenthunter/area.rb
|
147
|
+
- lib/apartmenthunter/cli.rb
|
148
|
+
- lib/apartmenthunter/export.rb
|
149
|
+
- lib/apartmenthunter/scraper-inprog.rb
|
150
|
+
- lib/apartmenthunter/scraper.rb
|
151
|
+
- lib/apartmenthunter/test.rb
|
152
|
+
- lib/apartmenthunter/version.rb
|
153
|
+
homepage: ''
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
metadata: {}
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.4.5.1
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: CLI based scraper to find apartments in the NYC area.
|
177
|
+
test_files: []
|