new_eugene_listing_cli 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2ce427b4eafb0da2bc036a4a00f331dd37c19f3770321e6f181e8411d86000b6
4
+ data.tar.gz: c020a5e6448489d3a4374b045952c4dff2ab8c060b5e07ba2795ce9a0fd928f7
5
+ SHA512:
6
+ metadata.gz: 7de86174c98d5d3ac043d780cfeebeee94030e4d0b62f0bbe18f555add94bb0cf17caffd91843a06f4c0afe0c4b97e0478ce11f300b8f0d8f8a1a36516260f20
7
+ data.tar.gz: 6fc3c3e67e8d8e4dcc2256e553910aa08af5ba0012018d4141f287b39835b11ef984b747b0ee5e8e8f509675c5a1e774bc451832ee4a4d51df85fc40cb986960
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/environment.rb'
3
+
4
+ NewEugeneListingCli::CLI.new.call
@@ -0,0 +1,8 @@
1
+ require 'nokogiri'
2
+ require 'pry'
3
+ require 'open-uri'
4
+
5
+ require_relative "../lib/new_eugene_listing_cli/version"
6
+ require_relative "../lib/new_eugene_listing_cli/cli"
7
+ require_relative "../lib/new_eugene_listing_cli/listing"
8
+ require_relative "../lib/new_eugene_listing_cli/scraper"
@@ -0,0 +1,46 @@
1
+ class NewEugeneListingCli::CLI
2
+
3
+ def call
4
+ NewEugeneListingCli::Scraper.new.build_properties
5
+ display_listings
6
+ menu
7
+ close
8
+ end
9
+
10
+ def display_listings
11
+ puts "The following are property listings in Eugene that are less than 24 hours old:"
12
+ @all = NewEugeneListingCli::Listing.all
13
+ @all.each.with_index(1) do |listing, i|
14
+ puts "#{i}. #{listing.address} -- #{listing.price} -- #{listing.bedrooms}bd -- #{listing.bathrooms}ba"
15
+ puts " #{listing.url}"
16
+ end
17
+ end
18
+
19
+ def menu
20
+ input = nil
21
+ while input != "exit"
22
+ puts "Please enter the number of the property you would like to see more information about or 'listings' to see the listings again or 'exit':"
23
+ input = gets.strip.downcase
24
+
25
+ if input.to_i > 0
26
+ this_listing = @all[input.to_i - 1]
27
+ puts "ADDRESS: #{this_listing.address}"
28
+ puts "PRICE: #{this_listing.price}"
29
+ puts "BEDROOM(S): #{this_listing.bedrooms}"
30
+ puts "BATHROOM(S): #{this_listing.bathrooms}"
31
+ puts "SQUARE FOOTAGE: #{this_listing.sq_feet}"
32
+ puts "PROPERTY TYPE: #{this_listing.property_type}"
33
+ puts "DESCRIPTION: #{this_listing.property_description}"
34
+ elsif input == 'listings'
35
+ display_listings
36
+ else
37
+ "I'm sorry, I don't understand. Please enter the number of the property you would like to see more information about:"
38
+ end
39
+ end
40
+ end
41
+
42
+ def close
43
+ puts "Thank you for using. Hope to see you again soon!"
44
+ end
45
+
46
+ end
@@ -0,0 +1,39 @@
1
+ class NewEugeneListingCli::Listing
2
+ attr_accessor :address, :price, :bedrooms, :bathrooms, :url, :sq_feet, :property_type, :property_description
3
+
4
+ @@all = []
5
+
6
+ def self.all
7
+ @@all
8
+ end
9
+
10
+ def initialize(address = nil, price = nil, bedrooms = nil, bathrooms = nil, url = nil)
11
+ @address = address
12
+ @price = price
13
+ @bedrooms = bedrooms
14
+ @bathrooms = bathrooms
15
+ @url = url
16
+ @@all << self
17
+ end
18
+
19
+ def self.new_from_index_page(p)
20
+ self.new(p.css(".addressDetail .h6").text.strip, p.css(".cardPrice").text.strip, p.css("[data-auto-test='beds']").text.gsub("bd", "").strip,
21
+ p.css("[data-auto-test='baths']").text.gsub("ba", "").strip, "https://www.trulia.com" + p.css("a")[0]["href"].strip)
22
+ end
23
+
24
+ def sq_feet
25
+ @sq_feet ||= doc.css(".miniCol12 ul li")[1].text.strip
26
+ end
27
+
28
+ def property_type
29
+ @property_type ||= doc.css(".xsColOffset4 li")[0].text.strip
30
+ end
31
+
32
+ def property_description
33
+ @property_description ||= doc.css("p#propertyDescription").text.strip
34
+ end
35
+
36
+ def doc
37
+ @doc = Nokogiri::HTML(rpage = open(self.url, "User-Agent" => "User").read)
38
+ end
39
+ end
@@ -0,0 +1,20 @@
1
+ class NewEugeneListingCli::Scraper
2
+
3
+ def get_page
4
+ Nokogiri::HTML(rpage = open("https://www.trulia.com/for_sale/Eugene,OR/date;d_sort/", "User-Agent" => "User").read)
5
+ end
6
+
7
+ def scrape_properties_index
8
+ listings = self.get_page.css(".xsCol12Landscape")
9
+ listings.map do |listing|
10
+ if listing.css(".typeHighlight").text == "< 1 Day on Trulia"
11
+ listing
12
+ end
13
+ end
14
+ end
15
+
16
+ def build_properties
17
+ scrape_properties_index.each {|p| if p != nil; NewEugeneListingCli::Listing.new_from_index_page(p) end}
18
+ end
19
+
20
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: new_eugene_listing_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "'Hector Ariceaga'"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-15 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: nokogiri
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
+ description: Provides information on new property listings in Eugene, Or. posted on
84
+ Trulia.
85
+ email:
86
+ - "'hector_ariceaga@hotmail.com'"
87
+ executables:
88
+ - new-eugene-listings
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - bin/new-eugene-listings
93
+ - config/environment.rb
94
+ - lib/new_eugene_listing_cli/cli.rb
95
+ - lib/new_eugene_listing_cli/listing.rb
96
+ - lib/new_eugene_listing_cli/scraper.rb
97
+ homepage: https://github.com/Hector-Ariceaga/new-eugene-listing-cli.git
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ - lib/new_eugene_listing_cli
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.7.7
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: New property listings in Eugene, Oregon.
122
+ test_files: []