sf_coffee 0.1.2

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: 78e47ec6cd27e89f64686a837f1da5fdd04ce12a
4
+ data.tar.gz: 4ef75fef417c804b64f4707747d7d6353a460912
5
+ SHA512:
6
+ metadata.gz: 7fc3cc436ec4ca764bdc26694c465b94776bc47f0f319a688a7fbbf914b00af9a23e796f706265ed9fe49da8072e41083a22b56df0870f1444012afd3e217165
7
+ data.tar.gz: f96da14525d3af576b86e4f67c44efe4ac10345cababf882be722480a690432e0111ddab9b775a930ff99fd60b17b4b42a405ade124f39217573e2af8ef3f64e
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.ipynb_checkpoints/
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.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sf_coffee.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 nothingisfunny
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,54 @@
1
+ # SfCoffee
2
+
3
+ Scraper for popular San Francisco coffee shop locations. Collects information from Starbucks API, Peet's Coffee and Tea, and Philz Coffee websites. Lists information for each store, including name, address, and phone number, allows one to search for nearest locations by ZIP Code.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sf_coffee'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install sf_coffee
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ sf_coffee #runs the CLI
25
+ ```
26
+
27
+ ```ruby
28
+ require 'sf_coffee'
29
+
30
+ SfCoffee::Scraper.starbucks #lists all Starbucks locations in SF
31
+
32
+ ```
33
+ ###Example results
34
+ ```ruby
35
+ [{:name=>"Starbucks Presidio & Letterman", :address=>"1 Letterman Drive, Building C, Letterman Digital Arts Center, San Francisco", :phone=>"415-441-1740", :zip_code=>"94129"},
36
+ {:name=>"Starbucks Third & Market", :address=>"7 Third Street, Third & Market, San Francisco", :phone=>"4159799530", :zip_code=>"94103"},
37
+ {:name=>"Starbucks Safeway - San Francisco #995", :address=>"1335 Webster, San Francisco", :phone=>"415-921-4557", :zip_code=>"94115"} ... ]
38
+ ```
39
+
40
+ ## Development
41
+
42
+ 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.
43
+
44
+ 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).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nothingisfunny/sf-coffee-cli-gem.
49
+
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
54
+
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/sf_coffee ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/sf_coffee'
3
+
4
+ SfCoffee::CLI.new.call
data/lib/sf_coffee.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'colorize'
4
+ require_relative './sf_coffee/version'
5
+ require_relative './sf_coffee/cli'
6
+ require_relative './sf_coffee/coffee_scraper'
7
+
8
+
9
+
10
+
@@ -0,0 +1,119 @@
1
+ require_relative '../sf_coffee'
2
+
3
+ class SfCoffee::CLI
4
+ ZIP_CODES = [94102, 94103, 94104,
5
+ 94105, 94107, 94108,
6
+ 94109, 94110, 94111,
7
+ 94112, 94114, 94115,
8
+ 94116, 94117, 94118,
9
+ 94121, 94122, 94123,
10
+ 94124, 94127, 94129,
11
+ 94130, 94131, 94132,
12
+ 94133, 94134, 94158]
13
+ def call
14
+ greeting
15
+ menu
16
+ goodbye
17
+ end
18
+
19
+ def greeting
20
+ puts "\n"
21
+ puts "Welcome to San Francisco coffee finder!"
22
+ end
23
+
24
+ def print_menu
25
+ puts "List all of the locations for your favorite coffee company by entering 1, 2, or 3:"
26
+ puts "\t1. Starbucks".yellow
27
+ puts "\t2. Peet's Coffee and Tea".yellow
28
+ puts "\t3. Philz Coffee".yellow
29
+ puts "OR"
30
+ puts "Find the nearest coffeeshop, by entering your ZIP Code:"
31
+ end
32
+
33
+ def finish_session
34
+ puts "To finish your session type" + " exit.".red + " To return to the main menu type" + " menu".red + "."
35
+ input = gets.strip.downcase
36
+ while input != "exit" && input !="menu"
37
+ puts "Oops, something went wrong. Please try again.".red
38
+ input = gets.strip.downcase
39
+ end
40
+ if input == "menu"
41
+ self.menu
42
+ else
43
+ end
44
+ end
45
+
46
+ def valid_zipcode?(input)
47
+ ZIP_CODES.include?(input.to_i)
48
+ end
49
+
50
+ def menu
51
+ self.print_menu
52
+ input = gets.strip
53
+ until input == "exit" || input =="menu" || input =="1" || input =="2" || input =="3" || valid_zipcode?(input) == true
54
+ puts "Oops, something went wrong. Please choose a number from the menu, or enter a valid San Francisco zipcode".red
55
+ input = gets.strip
56
+ end
57
+ if input == "menu"
58
+ self.menu
59
+ end
60
+ if input == "1"
61
+ # lists all Starbucks locations
62
+ puts "Here is what we found for your request:".blue
63
+ SfCoffee::Scraper.starbucks.each_with_index do |store, index|
64
+ puts "#{index+1}. Store name: ".yellow + "#{store[:name]}".yellow
65
+ puts "Address: #{store[:address]}, #{store[:zip_code]}".white
66
+ puts "Phone: #{store[:phone]}".white
67
+ end
68
+ self.finish_session
69
+ elsif input == "2"
70
+ #lists all Peet's Coffee and Tea locations
71
+ puts "Here is what we found for your request:".blue
72
+ SfCoffee::Scraper.peets.each_with_index do |store, index|
73
+ puts "#{index+1}. Store name: ".yellow + "#{store[:name]}".yellow
74
+ puts "Address: #{store[:address]}, #{store[:zip_code]}".white
75
+ puts "Phone: #{store[:phone]}".white
76
+ end
77
+ self.finish_session
78
+ elsif input == "3"
79
+ #lists all Philz Coffee locations
80
+ puts "Here is what we found for your request:".blue
81
+ SfCoffee::Scraper.philz.each_with_index do |store, index|
82
+ puts "#{index+1}. Store name: ".yellow + "#{store[:name]}".yellow
83
+ puts "Address: #{store[:address]}, #{store[:zip_code]}".white
84
+ puts "Phone: #{store[:phone]}".white
85
+ end
86
+ self.finish_session
87
+ elsif valid_zipcode?(input)
88
+ #prints the coffee shops in the area"
89
+ stores_with_zip = []
90
+ SfCoffee::Scraper.starbucks.each do |store|
91
+ if store[:zip_code] == input
92
+ stores_with_zip << store
93
+ end
94
+ end
95
+ SfCoffee::Scraper.peets.each do |store|
96
+ if store[:zip_code] == input
97
+ stores_with_zip << store
98
+ end
99
+ end
100
+ SfCoffee::Scraper.philz.each do |store|
101
+ if store[:zip_code] == input
102
+ stores_with_zip << store
103
+ end
104
+ end
105
+ puts "Here is what we found for your request:".blue
106
+ stores_with_zip.each_with_index do |store, index|
107
+ puts "#{index+1}. Store name: ".yellow + "#{store[:name]}".yellow
108
+ puts "Address: #{store[:address]}, #{store[:zip_code]}".white
109
+ puts "Phone: #{store[:phone]}".white
110
+ end
111
+ self.finish_session
112
+ end
113
+ end
114
+
115
+ def goodbye
116
+ puts "Thank you for using SF coffee fnder!".yellow
117
+ end
118
+
119
+ end
@@ -0,0 +1,65 @@
1
+ require_relative '../sf_coffee'
2
+
3
+ class SfCoffee::Scraper
4
+
5
+ def self.starbucks
6
+ stores = []
7
+ doc = Nokogiri::XML(open("https://openapi.starbucks.com/location/v1/stores?apikey=7b35m595vccu6spuuzu2rjh4&city=San%20Francisco&limit=50"))
8
+ doc.xpath("//xmlns:store").each do |store|
9
+ address = store.xpath("xmlns:address")
10
+ stores << {
11
+ :name => "Starbucks " + store.xpath("xmlns:name").text,
12
+ :address => [address.xpath("xmlns:streetAddressLine1").text(), address.xpath("xmlns:streetAddressLine2").text(), address.xpath("xmlns:streetAddressLine3").text(), address.xpath("xmlns:city").text()].delete_if{|i|i==""},
13
+ :phone => store.xpath("xmlns:phoneNumber").text,
14
+ :zip_code => address.xpath("xmlns:postalCode").text[0..4]
15
+ }
16
+ end
17
+ doc = Nokogiri::XML(open("https://openapi.starbucks.com/location/v1/stores?apikey=7b35m595vccu6spuuzu2rjh4&city=San%20Francisco&offset=50&limit=50"))
18
+ doc.xpath("//xmlns:store").each do |store|
19
+ address = store.xpath("xmlns:address")
20
+ stores << {
21
+ :name => "Starbucks " + store.xpath("xmlns:name").text,
22
+ :address => [address.xpath("xmlns:streetAddressLine1").text(), address.xpath("xmlns:streetAddressLine2").text(), address.xpath("xmlns:streetAddressLine3").text(), address.xpath("xmlns:city").text()].delete_if{|i|i==""},
23
+ :phone => store.xpath("xmlns:phoneNumber").text,
24
+ :zip_code => address.xpath("xmlns:postalCode").text[0..4]
25
+ }
26
+ end
27
+ stores.each{|store|store[:address] = store[:address].join(", ")}
28
+ stores
29
+ end
30
+
31
+ def self.peets
32
+ stores = []
33
+ doc = Nokogiri::HTML(open("http://www.peets.com/stores/peets-stores/stores-store-list.html"))
34
+ doc.css(".storeItem").each do |store|
35
+ stores << {
36
+ :name => store.children[0].text,
37
+ :address => (store.children[2].text()+","+store.children[4].text()),
38
+ :zip_code => store.children[0].text,
39
+ :phone => store.children[6].text.gsub(" ", "")
40
+ }
41
+ end
42
+ stores.delete_if{|store| !store[:name].include?("San Francisco—")}
43
+ stores.each {|store|store[:name] = "Peet's " + store[:name].split("—")[1]}
44
+ stores.each {|store|store[:zip_code] = store[:address].split("CA")[1].gsub(" ", "")}
45
+ stores.each{|store|store[:address] = store[:address][1..store[:address].length].split(/,* CA/)[0]}
46
+ stores
47
+ end
48
+
49
+ def self.philz
50
+ stores = []
51
+ doc = Nokogiri::HTML(open("http://www.philzcoffee.com/locations-sf"))
52
+ doc.css(".span4.mid").each do |store|
53
+ stores << {
54
+ :name => "Philz " + store.css("h1").text(),
55
+ :address => store.css(".location-text.text-left").text.gsub("ADDRESS: ",""),
56
+ :phone => store.css(".pull-left.location-phone-detail .text-right").text.gsub(" ", ""),
57
+ :zip_code => nil
58
+ }
59
+ end
60
+ stores.delete_if{|store| !store[:address].include?("San Francisco")}
61
+ stores.each {|store|store[:zip_code] = store[:address].split("CA")[1].gsub(" ", "")}
62
+ stores.each{|store|store[:address] = store[:address].split(",")[0]}
63
+ stores
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module SfCoffee
2
+ VERSION = "0.1.2"
3
+ end
data/sf_coffee.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sf_coffee/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sf_coffee"
8
+ spec.version = SfCoffee::VERSION
9
+ spec.authors = ["nothingisfunny"]
10
+ spec.email = ["if.the.kids.r.united@gmail.com"]
11
+
12
+ spec.summary = %q{Scraper for popular San Francisco coffee shop locations.}
13
+ spec.description = %q{Lists information for Starbucks, Peet's, and Philz, including name address, and phone number, allows one to search for nearest locations by ZIP Code.}
14
+ spec.homepage = "https://github.com/nothingisfunny/sf-coffee-cli-gem"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
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 = "bin"
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec"
33
+
34
+ spec.add_runtime_dependency "nokogiri"
35
+ spec.add_runtime_dependency 'colorize', '~> 0.7.7'
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sf_coffee
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - nothingisfunny
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-21 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: '0'
48
+ type: :development
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: nokogiri
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: colorize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.7.7
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.7.7
83
+ description: Lists information for Starbucks, Peet's, and Philz, including name address,
84
+ and phone number, allows one to search for nearest locations by ZIP Code.
85
+ email:
86
+ - if.the.kids.r.united@gmail.com
87
+ executables:
88
+ - sf_coffee
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/sf_coffee
100
+ - lib/sf_coffee.rb
101
+ - lib/sf_coffee/cli.rb
102
+ - lib/sf_coffee/coffee_scraper.rb
103
+ - lib/sf_coffee/version.rb
104
+ - sf_coffee.gemspec
105
+ homepage: https://github.com/nothingisfunny/sf-coffee-cli-gem
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ allowed_push_host: https://rubygems.org
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.6.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Scraper for popular San Francisco coffee shop locations.
130
+ test_files: []