internet_near_me 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a167a8bc0877aab9ed947dd1323ca1a0d6961a8d
4
+ data.tar.gz: 3c1132b442705ace6495ed1752d47995598e7567
5
+ SHA512:
6
+ metadata.gz: 83f1ac5a61a7148440666b158cec0ea94ee84f08eaee2253dc46464948dd49835d1ca789554f026ce6eab232eb5299f9ef4bf72ad39155d28d817f18fe6e625a
7
+ data.tar.gz: a130cd6961ac0a338ccd6255174fba8fde5cba0a53816f570cc8d1c1173e969c52254483ceefb31db92a53d7f05e5a7ee585927fd67e644c81c462ccaf3da8f3
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
@@ -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 lukegrecki@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
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in internet_near_me.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 lukegrecki
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,88 @@
1
+ # internet_near_me
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'internet_near_me'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ gem install internet_near_me
18
+
19
+ ## Usage
20
+
21
+ Open it with
22
+
23
+ internet_near_me
24
+
25
+ Then enter a zip code
26
+
27
+ Please enter your zip code:
28
+ 10023
29
+
30
+ It will display a list of the 10 nearest internet cafes:
31
+
32
+ Internet cafes near 10023:
33
+ --------------------
34
+ 1.
35
+ Cafe Noi Espresso Bar
36
+ 387 Amsterdam Ave
37
+ New York, NY 10024
38
+ --------------------
39
+ 2.
40
+ Irving Farm Coffee Roasters
41
+ 224 W 79th St
42
+ New York, NY 10024
43
+ --------------------
44
+ 3.
45
+ Aroma Espresso Bar
46
+ 161 W 72nd St
47
+ New York, NY 10023
48
+ --------------------
49
+ 4.
50
+ David Rubenstein Atrium
51
+ 61 W 62nd St
52
+ New York, NY 10023
53
+ --------------------
54
+ 5.
55
+ Mille-Feuille Bakery
56
+ 2175 Broadway
57
+ New York, NY 10036
58
+ --------------------
59
+ ...
60
+
61
+ You can then get details on one by entering a number:
62
+
63
+ Enter a number to get more details or 'back' to enter a new zip code:
64
+ 1
65
+
66
+ --------------------
67
+ Cafe Noi Espresso Bar
68
+ (212) 580-1315
69
+ Today: 7:00 am - 7:00 pm
70
+ 4.0 stars (75 reviews)
71
+ $$
72
+
73
+ You can then either enter `back` to change the zip code or another cafe number
74
+ to get the details of. At any time you can type `exit` to leave the program.
75
+
76
+ ## Development
77
+
78
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lukegrecki/internet_near_me. 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.
83
+
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
88
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "internet_near_me"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require "bundler/setup"
2
+
3
+ require "internet_near_me"
4
+ require "open-uri"
5
+ require "pry"
6
+ require "nokogiri"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../config/environment"
4
+
5
+ InternetNearMe::CLI.new.call
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'internet_near_me/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "internet_near_me"
8
+ spec.version = InternetNearMe::VERSION
9
+ spec.authors = ["lukegrecki"]
10
+ spec.email = ["lukegrecki@gmail.com"]
11
+
12
+ spec.summary = "Look up local internet cafes and get their details via yelp."
13
+ spec.homepage = "https://github.com/lukegrecki/internet_near_me"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables << "internet_near_me"
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "nokogiri", "1.6.7.2"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "pry"
27
+ end
@@ -0,0 +1,78 @@
1
+ class InternetNearMe::CLI
2
+ attr_accessor :zip_code, :exit
3
+
4
+ def call
5
+ welcome
6
+ loop do
7
+ if !exit
8
+ get_zip_code
9
+ exit ? break : get_more_details(list_internet_cafes)
10
+ else
11
+ break
12
+ end
13
+ end
14
+ goodbye
15
+ end
16
+
17
+ def welcome
18
+ puts "Welcome to internet_near_me! Enter 'exit' at any time to exit."
19
+ self.exit = false
20
+ end
21
+
22
+ def goodbye
23
+ puts "Goodbye!"
24
+ end
25
+
26
+ def get_zip_code
27
+ puts "Please enter your zip code:"
28
+ input = gets.strip
29
+ if input == 'exit'
30
+ self.exit = true
31
+ else
32
+ self.zip_code = input
33
+ end
34
+ end
35
+
36
+ def list_internet_cafes
37
+ puts "Internet cafes near #{zip_code}:"
38
+ internet_cafes = InternetNearMe::Scraper.new.scrape_by_zip_code(zip_code)
39
+ internet_cafes.each.with_index(1) do |internet_cafe, index|
40
+ render_divider
41
+ puts "#{index}."
42
+ puts internet_cafe.name
43
+ puts internet_cafe.address
44
+ end
45
+ render_divider
46
+ internet_cafes
47
+ end
48
+
49
+ def get_more_details(internet_cafes)
50
+ loop do
51
+ puts "Enter a number to get more details or 'back' to enter a new zip code:"
52
+ input = gets.strip
53
+ if input == 'back'
54
+ break
55
+ elsif input == 'exit'
56
+ self.exit = true
57
+ break
58
+ else
59
+ internet_cafe = InternetNearMe::Scraper.new.scrape_details(internet_cafes[input.to_i - 1])
60
+ render_divider
61
+ puts internet_cafe.name
62
+ puts internet_cafe.phone
63
+ puts "Today: #{internet_cafe.hours}"
64
+ puts "#{internet_cafe.rating} (#{internet_cafe.number_of_reviews} reviews)"
65
+ puts internet_cafe.price
66
+ puts internet_cafe.website
67
+ render_divider
68
+ end
69
+ end
70
+ end
71
+
72
+ private
73
+
74
+ def render_divider
75
+ puts "--------------------"
76
+ end
77
+
78
+ end
@@ -0,0 +1,16 @@
1
+ class InternetNearMe::InternetCafe
2
+ attr_accessor :name, :address, :price, :url, :rating, :hours, :phone,
3
+ :website, :number_of_reviews
4
+
5
+ def self.create_collection(internet_cafe_hashes)
6
+ internet_cafe_hashes.map do |internet_cafe_hash|
7
+ self.new(internet_cafe_hash)
8
+ end
9
+ end
10
+
11
+ def initialize(internet_cafe_hash)
12
+ internet_cafe_hash.each do |attribute, value|
13
+ self.send("#{attribute}=", value)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,42 @@
1
+ class InternetNearMe::Scraper
2
+
3
+ REQUEST_HEADERS = { "User-Agent" => "Ruby/#{RUBY_VERSION}",
4
+ "From" => "internet_near_me",
5
+ "Referer" => "http://www.ruby-lang.org/" }
6
+
7
+ def scrape_details(internet_cafe)
8
+ url = "http://www.yelp.com" + internet_cafe.url
9
+ doc = Nokogiri::HTML(open(url, REQUEST_HEADERS))
10
+
11
+ # binding.pry
12
+ internet_cafe.rating = doc.css(".rating-info .star-img").attribute("title")
13
+ .value.gsub("star rating", "stars")
14
+ internet_cafe.number_of_reviews = doc.css(".rating-info .review-count span").text.strip
15
+ internet_cafe.hours = doc.css(".hour-range").text
16
+ internet_cafe.phone = doc.css(".biz-phone").text.strip
17
+ internet_cafe.website = doc.css(".biz-website a").text.strip
18
+ internet_cafe
19
+ end
20
+
21
+ def scrape_by_zip_code(zip_code)
22
+ url = "http://www.yelp.com/search?find_desc=Internet+Cafes&find_loc=#{zip_code}"
23
+ doc = Nokogiri::HTML(open(url, REQUEST_HEADERS))
24
+
25
+ internet_cafe_hashes = doc.css(".search-results-content li.regular-search-result").map do |search_result|
26
+ {
27
+ name: search_result.css("a.biz-name").text.strip,
28
+ address: search_result.css("address").inner_html.gsub("<br>", "\n").strip,
29
+ price: search_result.css(".price-range").text.strip,
30
+ url: search_result.css("a.biz-name").attribute("href").value
31
+ }
32
+ end
33
+
34
+ create_internet_cafes(internet_cafe_hashes)
35
+ end
36
+
37
+ private
38
+
39
+ def create_internet_cafes(internet_cafe_hashes)
40
+ InternetNearMe::InternetCafe.create_collection(internet_cafe_hashes)
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module InternetNearMe
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "internet_near_me/version"
2
+ require "internet_near_me/cli"
3
+ require "internet_near_me/scraper"
4
+ require "internet_near_me/internet_cafe"
5
+
6
+ module InternetNearMe
7
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: internet_near_me
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - lukegrecki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.7.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.7.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.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:
84
+ email:
85
+ - lukegrecki@gmail.com
86
+ executables:
87
+ - internet_near_me
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - config/environment.rb
102
+ - exe/internet_near_me
103
+ - internet_near_me.gemspec
104
+ - lib/internet_near_me.rb
105
+ - lib/internet_near_me/cli.rb
106
+ - lib/internet_near_me/internet_cafe.rb
107
+ - lib/internet_near_me/scraper.rb
108
+ - lib/internet_near_me/version.rb
109
+ homepage: https://github.com/lukegrecki/internet_near_me
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.4.5
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Look up local internet cafes and get their details via yelp.
133
+ test_files: []