couchsurfing 0.1.0.alpha
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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/couchsurfing +6 -0
- data/bin/setup +8 -0
- data/couchsurfing.gemspec +31 -0
- data/lib/couchsurfing/cli.rb +142 -0
- data/lib/couchsurfing/host.rb +47 -0
- data/lib/couchsurfing/place.rb +46 -0
- data/lib/couchsurfing/scraper.rb +89 -0
- data/lib/couchsurfing/version.rb +3 -0
- data/lib/couchsurfing.rb +8 -0
- data/spec.md +15 -0
- metadata +157 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 7091f4bdd2c76102d6dc455a7149d55ef06e497a
|
|
4
|
+
data.tar.gz: 97c9ce31a6535ca049878df203fd9586c119b302
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c562151a43fd2b77ab87d16eb81ef607c777e0c548cb58bbf01ebd357e08c9372712c45cdcee15572486faf53bab1715135a0b22c7eb72541ef517344a3eedf7
|
|
7
|
+
data.tar.gz: 5a09ffa2d9f085529f4204c66c71baa4d657d1246479a0724935fcfa52d8a0e1a8dc0270228fbd731288bc1c594b89e58af53bd2a0dff81d29a59a526f916dc6
|
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 lifechangingstuff@gmail.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/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 NickisKnowledge
|
|
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,41 @@
|
|
|
1
|
+
# Couchsurfing
|
|
2
|
+
|
|
3
|
+
Welcome to the Couchsurfing Gem! This Ruby gem provides the easiest command line interface that allows you to travel around the world and find FREE lodging, by connecting you to potential host in the area thanks to the Couchsurfing website.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'couchsurfing'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install couchsurfing
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Run: `couchsurfing` after installing the gem.
|
|
24
|
+
|
|
25
|
+
## Development
|
|
26
|
+
|
|
27
|
+
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.
|
|
28
|
+
|
|
29
|
+
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).
|
|
30
|
+
|
|
31
|
+
## Contributing
|
|
32
|
+
|
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[NickisKnowledge]/couchsurfing. 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.
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
38
|
+
|
|
39
|
+
## Code of Conduct
|
|
40
|
+
|
|
41
|
+
Everyone interacting in the Couchsurfing project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/couchsurfing/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 "couchsurfing"
|
|
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/couchsurfing
ADDED
data/bin/setup
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "couchsurfing/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'couchsurfing'
|
|
8
|
+
spec.version = Couchsurfing::VERSION
|
|
9
|
+
spec.authors = ["NickisKnowledge"]
|
|
10
|
+
spec.email = ["lifechangingstuff@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = 'This is a Flatiron CLI Data Gem Project.'
|
|
13
|
+
spec.description = 'This gem connects travelers to hosts across the country that have available housing accommodations.'
|
|
14
|
+
spec.homepage = ''
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
# spec.bindir = "exe"
|
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
27
|
+
spec.add_development_dependency "pry", "~> 0.10.4"
|
|
28
|
+
spec.add_development_dependency "pry-byebug", "~> 3.4", ">= 3.4.2"
|
|
29
|
+
|
|
30
|
+
spec.add_dependency "nokogiri"
|
|
31
|
+
end
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# CLI controller deals with user interactions
|
|
2
|
+
class Couchsurfing::CLI
|
|
3
|
+
attr_accessor :places
|
|
4
|
+
|
|
5
|
+
def initialize
|
|
6
|
+
@places = Couchsurfing::Place.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def start
|
|
10
|
+
begin
|
|
11
|
+
info = get_continents
|
|
12
|
+
info = get_countries(info) unless info == 'exit' || info == 'error'
|
|
13
|
+
info = get_cities(info) unless info == 'exit' || info == 'error'
|
|
14
|
+
info = get_hosts(info) unless info == 'exit' || info == 'error'
|
|
15
|
+
info = host(info) unless info == 'exit' || info == 'error'
|
|
16
|
+
reading_time unless info == 'exit' || info == 'error'
|
|
17
|
+
end while info != 'exit'
|
|
18
|
+
exit_message
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def prompt_for_continents
|
|
22
|
+
puts "Select a number with the continent you would like to visit.\n" \
|
|
23
|
+
"Type 'exit' to quit the program.\n\n"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def get_continents
|
|
27
|
+
prompt_for_continents
|
|
28
|
+
z = display_continents
|
|
29
|
+
info = get_info(z)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get_info(int)
|
|
33
|
+
info = gets.strip.downcase
|
|
34
|
+
return info if info == 'exit'
|
|
35
|
+
info = info.to_i if info.scan(/^[\d]+$/).any?
|
|
36
|
+
return info if (1..int).cover?(info)
|
|
37
|
+
invalid
|
|
38
|
+
'error'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def display_continents
|
|
42
|
+
@places.continents.each.with_index do |c, i|
|
|
43
|
+
puts "#{i + 1}. #{c}"
|
|
44
|
+
end
|
|
45
|
+
puts "\n"
|
|
46
|
+
|
|
47
|
+
@places.continents.count
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def get_countries(input)
|
|
51
|
+
@places.continent_selection(input)
|
|
52
|
+
prompt_for_countries
|
|
53
|
+
z = display_countries
|
|
54
|
+
info = get_info(z)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def prompt_for_countries
|
|
58
|
+
puts "\nChoose the number of the country you would like to tour, " \
|
|
59
|
+
"or type exit.\n\n"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def display_countries
|
|
63
|
+
@places.countries.each_with_index do |c, i|
|
|
64
|
+
puts "#{i + 1}. #{c}"
|
|
65
|
+
end
|
|
66
|
+
puts "\n"
|
|
67
|
+
|
|
68
|
+
@places.countries.count
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def get_cities(input)
|
|
72
|
+
@places.country_selection(input)
|
|
73
|
+
prompt_for_cities
|
|
74
|
+
z = display_cities
|
|
75
|
+
info = get_info(z)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def prompt_for_cities
|
|
79
|
+
puts "\nPick a number with the city you want to explore, or type exit.\n\n"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def display_cities
|
|
83
|
+
@places.cities.each_with_index do |c, i|
|
|
84
|
+
puts "#{i + 1}. #{c}"
|
|
85
|
+
end
|
|
86
|
+
puts "\n"
|
|
87
|
+
|
|
88
|
+
@places.cities.count
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def get_hosts(input)
|
|
92
|
+
@places.city_selection(input)
|
|
93
|
+
prompt_for_hosts
|
|
94
|
+
z = display_hosts
|
|
95
|
+
info = get_info(z)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def prompt_for_hosts
|
|
99
|
+
puts "\nPlease wait while we find your hosts or type exit.\n\n"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def display_hosts
|
|
103
|
+
@comperes = Couchsurfing::Host.new(@places)
|
|
104
|
+
puts "Enter the number of the name that interests you, or type exit.\n\n"
|
|
105
|
+
@comperes.hosts_selection.each_with_index do |name, i|
|
|
106
|
+
puts "#{i + 1}. #{name.split.map(&:capitalize) * ' '}"
|
|
107
|
+
end
|
|
108
|
+
puts "\n"
|
|
109
|
+
|
|
110
|
+
@comperes.hosts_selection.count
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def host(input)
|
|
114
|
+
z = @comperes.selected_host(input)
|
|
115
|
+
server_trick if z == []
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def server_trick
|
|
119
|
+
puts "\nI'm sorry the couchsurfing server would not let" \
|
|
120
|
+
" me have information about this person.\n\n"
|
|
121
|
+
sleep 2
|
|
122
|
+
puts "Darn thing can be so uncooperative . . .\n\n"
|
|
123
|
+
sleep 2
|
|
124
|
+
puts "Please select another destination!\n\n"
|
|
125
|
+
sleep 2
|
|
126
|
+
puts "Safe travels!\n\nHope you have a ball!!! =) ;-D\n\n\n\n"
|
|
127
|
+
sleep 2
|
|
128
|
+
'error'
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def reading_time
|
|
132
|
+
sleep 10
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def exit_message
|
|
136
|
+
puts "\nHave a great time with your new host =D"
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def invalid
|
|
140
|
+
puts "Your selection was invalid. Please choose a number from the list.\n\n"
|
|
141
|
+
end
|
|
142
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Host class captures and formats host information returned from Scraper
|
|
2
|
+
class Couchsurfing::Host
|
|
3
|
+
attr_accessor :hosts, :scraper, :names
|
|
4
|
+
|
|
5
|
+
def initialize(obj)
|
|
6
|
+
continent = make_url(obj.continent)
|
|
7
|
+
country = make_url(obj.country)
|
|
8
|
+
city = make_url(obj.city)
|
|
9
|
+
@scraper = Couchsurfing::Scraper.new
|
|
10
|
+
@hosts = @scraper.get_host_pages(continent, country, city)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def make_url(selection)
|
|
14
|
+
selection.downcase.tr(' ', '-')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def hosts_selection
|
|
18
|
+
@names = []
|
|
19
|
+
@hosts = @hosts.sample(5)
|
|
20
|
+
@hosts.each do |info|
|
|
21
|
+
@names << info['name']
|
|
22
|
+
end
|
|
23
|
+
@names.sort!
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def selected_host(num)
|
|
27
|
+
i = num - 1
|
|
28
|
+
host = @names[i]
|
|
29
|
+
about_host(host)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def about_host(choice_h)
|
|
33
|
+
host_info = @hosts.select { |person| person['name'] == choice_h }
|
|
34
|
+
url = host_info[0]['url']
|
|
35
|
+
|
|
36
|
+
about_host = @scraper.scrape_host_page(url) unless about_host == []
|
|
37
|
+
about_host.each do |descript|
|
|
38
|
+
puts "\n\nHello as you know my name is #{descript['name']}.\n\n"
|
|
39
|
+
puts "I am a#{descript['age_sex'].split(',')[1]}, who is" \
|
|
40
|
+
"#{descript['age_sex'].split(',')[0]} years old.\n\n"
|
|
41
|
+
descript['about_me'].each { |k, v| puts "#{k}\n#{v.tr("\n", '')}\n\n" }
|
|
42
|
+
|
|
43
|
+
puts "You should definitely come stay with me! We'll have a " \
|
|
44
|
+
"blast! ; )\n\n\n\n"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Place class handels on geographical data returned from Scraper class
|
|
2
|
+
class Couchsurfing::Place
|
|
3
|
+
attr_accessor :continents, :countries, :cities, :locations, :continent, \
|
|
4
|
+
:country, :city
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@continents = []
|
|
8
|
+
z = Couchsurfing::Scraper.new
|
|
9
|
+
@locations = z.scrape_locations
|
|
10
|
+
@locations.each { |location| @continents.sort! << location['continent'] }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def continent_selection(num)
|
|
14
|
+
i = num - 1
|
|
15
|
+
@continent = @continents[i]
|
|
16
|
+
select_countries(@continent)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def select_countries(choice_c)
|
|
20
|
+
@countries = []
|
|
21
|
+
|
|
22
|
+
@hash = @locations.select { |location| location['continent'] == choice_c }
|
|
23
|
+
|
|
24
|
+
@hash[0]['provinces'].each { |hash| @countries << hash['country'] }
|
|
25
|
+
|
|
26
|
+
@countries = @countries.sample(5).sort!
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def country_selection(num)
|
|
30
|
+
i = num - 1
|
|
31
|
+
@country = @countries[i]
|
|
32
|
+
select_cities(@country)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def select_cities(choice_c)
|
|
36
|
+
hash = @hash[0]['provinces']
|
|
37
|
+
hash.select { |c| @cities = c['cities'] if c['country'] == choice_c }
|
|
38
|
+
|
|
39
|
+
@cities = @cities.sample(5).sort!
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def city_selection(num)
|
|
43
|
+
i = num - 1
|
|
44
|
+
@city = @cities[i]
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Scrapes 'couchsurfing.com'
|
|
2
|
+
class Couchsurfing::Scraper
|
|
3
|
+
def scrape_locations
|
|
4
|
+
doc = Nokogiri::HTML(open('https://www.couchsurfing.com/places'))
|
|
5
|
+
structure = doc.css('#section_places div:nth-child(4) div div' \
|
|
6
|
+
' div.pure-u-1.pure-u-md-15-24 div')
|
|
7
|
+
regions = structure.css('.cs-sitemap-region')
|
|
8
|
+
|
|
9
|
+
locations = []
|
|
10
|
+
c = structure.css('h2 a').count
|
|
11
|
+
(0...c).each do |i|
|
|
12
|
+
n = 0
|
|
13
|
+
area = {}
|
|
14
|
+
continent = (structure.css('h2 a')[i]).text
|
|
15
|
+
area['continent'] = continent
|
|
16
|
+
countries = (regions[i]).css('h3 a').map(&:text)
|
|
17
|
+
|
|
18
|
+
area['provinces'] = []
|
|
19
|
+
countries.map do |country|
|
|
20
|
+
p = {}
|
|
21
|
+
area['provinces'] << p
|
|
22
|
+
c1 = (regions[i]).css("ul:nth-child(#{(n += 2)})").text
|
|
23
|
+
cities = c1.split("\n").collect(&:strip).reject!(&:empty?)
|
|
24
|
+
|
|
25
|
+
p['country'] = country
|
|
26
|
+
p['cities'] = cities
|
|
27
|
+
end
|
|
28
|
+
locations << area
|
|
29
|
+
end
|
|
30
|
+
locations
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def get_host_pages(continent, country, city)
|
|
34
|
+
url = 'https://www.couchsurfing.com/places/' \
|
|
35
|
+
+ continent + '/' + country + '/' + city
|
|
36
|
+
|
|
37
|
+
doc = Nokogiri::HTML(open(url))
|
|
38
|
+
host_info = doc.css('div.multicolumn.mod-flex.mod-wrap')
|
|
39
|
+
|
|
40
|
+
hosts = []
|
|
41
|
+
host_info.css('a.text.mod-truncated.mod-black.mod-w-90').each do |info|
|
|
42
|
+
host = {}
|
|
43
|
+
host['name'] = info.text.strip.split("\n").join
|
|
44
|
+
host['url'] = info['href']
|
|
45
|
+
hosts << host
|
|
46
|
+
end
|
|
47
|
+
hosts
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def scrape_host_page(host_url)
|
|
51
|
+
url = 'https://www.couchsurfing.com' + host_url
|
|
52
|
+
doc = Nokogiri::HTML(open(url))
|
|
53
|
+
|
|
54
|
+
host = []
|
|
55
|
+
profile = {}
|
|
56
|
+
|
|
57
|
+
host_name = doc.css('div.profile-sidebar__user-info span a span').text
|
|
58
|
+
profile['name'] = host_name
|
|
59
|
+
|
|
60
|
+
z = doc.css('section:nth-child(3) div div div:nth-child(1) ul ' \
|
|
61
|
+
'li:nth-child(3)').text
|
|
62
|
+
profile['age_sex'] = z
|
|
63
|
+
|
|
64
|
+
about_me_section = doc.css('div:nth-child(5) section:nth-child(4) div')
|
|
65
|
+
|
|
66
|
+
person = {}
|
|
67
|
+
profile['about_me'] = person
|
|
68
|
+
|
|
69
|
+
if about_me_section.css('p:nth-child(2)').text == ''
|
|
70
|
+
person['About Me'] = about_me_section.css('p:nth-child(1)').text
|
|
71
|
+
else
|
|
72
|
+
person['About Me'] = about_me_section.css('p:nth-child(1)').text + ': ' + \
|
|
73
|
+
about_me_section.css('p:nth-child(2)').text unless \
|
|
74
|
+
about_me_section.css('p:nth-child(1)').text == ''
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
about_me_section.search('h2').each do |node|
|
|
78
|
+
if node.next_element.text.include?('COUCHSURFING')
|
|
79
|
+
person[node.text] = node.next_element.text + ': ' + \
|
|
80
|
+
node.next_element.next_element.text
|
|
81
|
+
else
|
|
82
|
+
person[node.text] = node.next_element.text \
|
|
83
|
+
unless node.next_element.text == ''
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
host << profile unless profile['name'] == ''
|
|
87
|
+
host
|
|
88
|
+
end
|
|
89
|
+
end
|
data/lib/couchsurfing.rb
ADDED
data/spec.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Provide a CLI
|
|
2
|
+
[x] -- I have a CLI class that allows the user to interact with data from the couchsurfing website.
|
|
3
|
+
|
|
4
|
+
CLI must provide access to data from a web page.
|
|
5
|
+
[x] -- web page: couchsurfing.com
|
|
6
|
+
|
|
7
|
+
The data provided must go at least one level deep, generally by showing the user a list of available data and then being able to drill down into a specific item.
|
|
8
|
+
[x] -- My specific item are the hosts. They get selected after the continent, country and city are selected.
|
|
9
|
+
|
|
10
|
+
The CLI application can not be a Music CLI application as that is too similiar to the other OO Ruby final project. Also please refrain from using Kickstarter as that was used for the scraping 'code along'. Look at the example domains below for inspiration.
|
|
11
|
+
[x] -- My gem has nothing to do with music and I'm not using Kickstarter.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Use good OO design patterns. You should be creating a collection of objects - not hashes.
|
|
15
|
+
[x] -- My object collection consist of the continent, country, city and then the host.
|
metadata
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: couchsurfing
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0.alpha
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- NickisKnowledge
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-08-24 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.15'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.15'
|
|
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.10.4
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.10.4
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: pry-byebug
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.4'
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: 3.4.2
|
|
79
|
+
type: :development
|
|
80
|
+
prerelease: false
|
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - "~>"
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '3.4'
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: 3.4.2
|
|
89
|
+
- !ruby/object:Gem::Dependency
|
|
90
|
+
name: nokogiri
|
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
type: :runtime
|
|
97
|
+
prerelease: false
|
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
description: This gem connects travelers to hosts across the country that have available
|
|
104
|
+
housing accommodations.
|
|
105
|
+
email:
|
|
106
|
+
- lifechangingstuff@gmail.com
|
|
107
|
+
executables:
|
|
108
|
+
- console
|
|
109
|
+
- couchsurfing
|
|
110
|
+
- setup
|
|
111
|
+
extensions: []
|
|
112
|
+
extra_rdoc_files: []
|
|
113
|
+
files:
|
|
114
|
+
- ".gitignore"
|
|
115
|
+
- ".rspec"
|
|
116
|
+
- ".travis.yml"
|
|
117
|
+
- CODE_OF_CONDUCT.md
|
|
118
|
+
- Gemfile
|
|
119
|
+
- LICENSE.txt
|
|
120
|
+
- README.md
|
|
121
|
+
- Rakefile
|
|
122
|
+
- bin/console
|
|
123
|
+
- bin/couchsurfing
|
|
124
|
+
- bin/setup
|
|
125
|
+
- couchsurfing.gemspec
|
|
126
|
+
- lib/couchsurfing.rb
|
|
127
|
+
- lib/couchsurfing/cli.rb
|
|
128
|
+
- lib/couchsurfing/host.rb
|
|
129
|
+
- lib/couchsurfing/place.rb
|
|
130
|
+
- lib/couchsurfing/scraper.rb
|
|
131
|
+
- lib/couchsurfing/version.rb
|
|
132
|
+
- spec.md
|
|
133
|
+
homepage: ''
|
|
134
|
+
licenses:
|
|
135
|
+
- MIT
|
|
136
|
+
metadata: {}
|
|
137
|
+
post_install_message:
|
|
138
|
+
rdoc_options: []
|
|
139
|
+
require_paths:
|
|
140
|
+
- lib
|
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - ">="
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '0'
|
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
|
+
requirements:
|
|
148
|
+
- - ">"
|
|
149
|
+
- !ruby/object:Gem::Version
|
|
150
|
+
version: 1.3.1
|
|
151
|
+
requirements: []
|
|
152
|
+
rubyforge_project:
|
|
153
|
+
rubygems_version: 2.4.8
|
|
154
|
+
signing_key:
|
|
155
|
+
specification_version: 4
|
|
156
|
+
summary: This is a Flatiron CLI Data Gem Project.
|
|
157
|
+
test_files: []
|