travel_inspiration 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dfe7ba8370b2d514764a0196e7e4e9c446ea4f8e
4
+ data.tar.gz: f6f4fac6110c68edb2a3caedca119c3fe61707fd
5
+ SHA512:
6
+ metadata.gz: 4fc90d0d7d388d8b0dcb8b132f4352cded375555cb3d8895e048f3da8bc3b2076735937727b5dd939b31660972ac2fc384d7012b4fc3a7da479d6ac2ad181a68
7
+ data.tar.gz: bc4654aecb1453e769aabd857678bb9d3fa0f365c90135c32998e6cf053b25e1f90785374d4283d1c9cf226cb4131e8259a5e7ef010a97402bdc52b4355b6a9f
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in travel_inspiration.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Lisa Huang
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,30 @@
1
+ # Travel Inspiration
2
+
3
+ This Ruby Gem provides a CLI to view 12 travel inspiration themes, sourced from [Lonely Planet](https://www.lonelyplanet.com/) website. Users can choose a theme and view the top 6 destinations, and drill-down to see more details of each destination.
4
+
5
+ ## Installation
6
+ You can install this gem by typing the following prompt in terminal:
7
+
8
+ ```gem install travel_inspiration```
9
+
10
+ The ```travel_inspiration``` CLI will be installed and you can run ```inspire_me``` to get a list of travel inspiration themes right in your command line.
11
+
12
+ ## Usage
13
+
14
+ Run: ```inspire_me``` after installing the gem.
15
+
16
+ ## Development
17
+
18
+ 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.
19
+
20
+ 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).
21
+
22
+ ## Contributing
23
+
24
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/travel_inspiration.
25
+
26
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://github.com/dannyd4315/worlds-best-restaurants-cli-gem/blob/master/contributor-covenant.org) code of conduct.
27
+
28
+ ## License
29
+
30
+ 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,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "travel_inspiration"
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/inspire_me ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "travel_inspiration"
5
+
6
+ TravelInspiration::CLI.new.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,8 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'pry'
4
+
5
+ require "travel_inspiration/version"
6
+ require "travel_inspiration/themes"
7
+ require "travel_inspiration/cli"
8
+
@@ -0,0 +1,92 @@
1
+ require 'pry'
2
+ require_relative 'themes.rb'
3
+ require_relative 'destinations.rb'
4
+ require_relative 'country.rb'
5
+ require 'colorize'
6
+ require 'readline'
7
+
8
+ module TravelInspiration
9
+ class CLI
10
+
11
+ def start
12
+ list_themes
13
+ end
14
+
15
+ def list_themes
16
+ puts "Hello! Which travel inspiration will you like to explore for your next trip?".green.bold
17
+ puts "\nPlease select a theme from 1 - 12".blue.bold
18
+ theme_arr = TravelInspiration::Theme.list_theme_names
19
+ puts theme_arr.map.with_index{|theme, index|
20
+ "\t#{index+1}. #{theme.name}"
21
+ }
22
+ puts "--------------------------------------------".black.on_white #horizontal divider
23
+ select_theme(theme_arr)
24
+ end
25
+
26
+ def select_theme(theme_arr)
27
+ input = nil
28
+
29
+ while true # user_input != "exit"
30
+ input = Readline.readline("Select theme 🛣 ", true).strip
31
+
32
+ goodbye if input.downcase === "exit"
33
+ input = input.to_i
34
+
35
+ if input > 0 && input < 13
36
+ puts "--------------------------------------------".black.on_white #horizontal divider
37
+ theme_name = theme_arr[input-1].name.strip
38
+ puts "Here are the top 6 destinations for #{theme_name.upcase}\n".green.bold
39
+ list_destinations(theme_name)
40
+ else
41
+ puts "That selection is not valid. Please select a theme from 1 - 12, or type exit."
42
+ end
43
+ end
44
+ end
45
+
46
+ def list_destinations(theme_name)
47
+ puts "Please select a destination from 1 - 6".blue.bold
48
+ country_arr = TravelInspiration::Destination.list_destination_names(theme_name)
49
+
50
+ puts country_arr.map.with_index{|d, index|
51
+ "\t#{index+1}. #{d.name}, #{d.continent}"
52
+ }
53
+ puts "--------------------------------------------".black.on_white #horizontal divider
54
+ select_country(country_arr)
55
+ end
56
+
57
+ def select_country(country_arr)
58
+ user_input = nil
59
+ while true # user_input != "exit"
60
+ user_input = Readline.readline("Select country 🗺 ", true).strip
61
+
62
+ goodbye if user_input.downcase === "exit"
63
+
64
+ country_choice = user_input.to_i
65
+
66
+ if country_choice > 0 && country_choice < 7
67
+ puts "--------------------------------------------".black.on_white #horizontal divider
68
+
69
+ #select country = array[country_choice]
70
+ chosen_country = country_arr[country_choice-1].name.upcase
71
+
72
+ puts "Here's some information about #{chosen_country}, and the best time to travel there!".green.bold
73
+ country_details(chosen_country)
74
+ else
75
+ puts "That selection is not valid. Please select a country from 1-6, or type exit."
76
+ end
77
+ end
78
+ end
79
+
80
+ def country_details(chosen_country)
81
+ country = TravelInspiration::Country.new(chosen_country)
82
+ puts country.country_info
83
+ end
84
+
85
+ def goodbye
86
+ puts "\nFarewell, traveler! May the wind take you somewhere new!".red.on_white.bold
87
+ exit
88
+ end
89
+ end
90
+ end
91
+
92
+ puts TravelInspiration::CLI.new.start
@@ -0,0 +1,67 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require_relative 'themes.rb'
4
+ require_relative 'destinations.rb'
5
+
6
+ module TravelInspiration
7
+ class Country
8
+ attr_accessor :name, :url, :high_season, :low_season, :best_visit_season, :summary_quote, :details
9
+
10
+ def initialize(name)
11
+ @name = name
12
+ end
13
+
14
+ def country_info
15
+ scrape_season #set seasonality information
16
+ scrape_info #set country name, summary_quote and details
17
+
18
+ puts "\t#{@best_visit_season}!
19
+ #{@high_season}\n
20
+ #{@low_season}\n"
21
+ puts "#{@summary_quote}".blue.on_yellow
22
+ puts @details
23
+ end
24
+
25
+ #scrape country information
26
+ def scrape_info
27
+ doc = Nokogiri::HTML(open(url))
28
+
29
+ info_url = doc.search("#introduction article.love-letter a").attr("href").text
30
+ info_page = Nokogiri::HTML(open(info_url))
31
+
32
+ @summary_quote = info_page.search("div.copy--body p.copy--feature").text
33
+
34
+ subtitles = info_page.search("div.copy--body h2").to_a
35
+ subtitles = subtitles.map {|s| s.text}
36
+
37
+ descriptions = info_page.search("div.copy--body p.copy--body").to_a
38
+ descriptions = descriptions.map {|d| d.text}
39
+ descriptions.reject!{|item|
40
+ item.downcase.end_with?("writer")
41
+ }
42
+
43
+ @details = subtitles.map.with_index{|title, index|
44
+ "\n" + title.upcase + "\n" + descriptions[index] + "\n"
45
+ }
46
+ end
47
+
48
+ #scrape best time to visit from Country/weather website
49
+ def scrape_season
50
+ doc = Nokogiri::HTML(open(url))
51
+
52
+ seasonality_url = doc.search("#survival-guide ul li:nth-child(2) a").attr("href").text #get country weather url
53
+ weather_pg = Nokogiri::HTML(open(seasonality_url))
54
+
55
+ #get high, low, and best time to visit information
56
+ @high_season = weather_pg.search("div.card--page__content p:nth-child(1)").text
57
+ @low_season = weather_pg.search("div.card--page__content p:nth-child(5)").first.text
58
+
59
+ shoulder_season = weather_pg.search("div.card--page__content p:nth-child(3)").first.text
60
+ @best_visit_season = "Best time to visit " + shoulder_season[16..-1]
61
+ end
62
+
63
+ def url
64
+ "https://www.lonelyplanet.com/" + @name.downcase.sub(" ", "-")
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,31 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ module TravelInspiration
5
+ class Destination
6
+ attr_accessor :name, :continent, :url
7
+
8
+ def self.list_destination_names(theme_name)
9
+ self.scrape_destinations(theme_name)
10
+ end
11
+
12
+ #scrape data using URL
13
+ def self.scrape_destinations(theme_name)
14
+ list = []
15
+
16
+ url = TravelInspiration::Theme.url_for_theme_name(theme_name)
17
+ doc = Nokogiri::HTML(open(url))
18
+ destinations = doc.search('div.SightsList-wrap a') #selects 6 destinations
19
+
20
+ destinations.map.with_index{ |destination, index|
21
+ new_destination = TravelInspiration::Destination.new #create destination instance
22
+ new_destination.name = destination.css('h5').text
23
+ new_destination.continent = destination.css('p').text
24
+ new_destination.url = destination.attr("href")
25
+ list[index] = new_destination
26
+ }
27
+ list.sort_by! {|obj| [obj.continent, obj.name]}
28
+ list
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ module TravelInspiration
5
+ class Theme
6
+ attr_accessor :name, :url
7
+
8
+ def self.list_theme_names
9
+ self.scrape_themes
10
+ end
11
+
12
+ def self.scrape_themes
13
+ themes_list = []
14
+ doc = Nokogiri::HTML(open("https://www.lonelyplanet.com/"))
15
+ themes = doc.search('div.slick-track a.slick-slide') #selects carousel slides
16
+ themes.each_with_index{|theme, index|
17
+ if index < 12 then
18
+ new_theme = TravelInspiration::Theme.new #create theme instance
19
+ new_theme.name = theme.css("p").text #assign theme name
20
+ new_theme.url = theme.attr("href") #assign theme url for destination #scraping
21
+ themes_list[index] = new_theme
22
+ end
23
+ }
24
+ themes_list
25
+ end
26
+
27
+ def self.url_for_theme_name(theme_name)
28
+ "https://www.lonelyplanet.com/#{theme_name.downcase.sub(" ", "-")}/"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module TravelInspiration
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "travel_inspiration/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "travel_inspiration"
8
+ spec.version = TravelInspiration::VERSION
9
+ spec.authors = ["Lisa Huang"]
10
+ spec.email = ["lisa.yc.huang@gmail.com"]
11
+
12
+ spec.summary = %q{"A ruby gem to view travel inspiration by themes"}
13
+ spec.description = %q{"A ruby gem to view Lonely Planet travel inspiration by themes. You will learn about the top 6 destinations!"}
14
+ spec.homepage = "https://github.com/lisaychuang/travel_inspiration_gem"
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{^exe/}) { |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 "pry", "~> 0.10.4"
27
+ spec.add_dependency "nokogiri", "~> 1.8"
28
+ spec.add_dependency "colorize", "~> 0.8.1"
29
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: travel_inspiration
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lisa Huang
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-12 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: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.4
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
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.8.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.1
83
+ description: '"A ruby gem to view Lonely Planet travel inspiration by themes. You
84
+ will learn about the top 6 destinations!"'
85
+ email:
86
+ - lisa.yc.huang@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/inspire_me
98
+ - bin/setup
99
+ - lib/travel_inspiration.rb
100
+ - lib/travel_inspiration/cli.rb
101
+ - lib/travel_inspiration/country.rb
102
+ - lib/travel_inspiration/destinations.rb
103
+ - lib/travel_inspiration/themes.rb
104
+ - lib/travel_inspiration/version.rb
105
+ - travel_inspiration.gemspec
106
+ homepage: https://github.com/lisaychuang/travel_inspiration_gem
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
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.10
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: '"A ruby gem to view travel inspiration by themes"'
130
+ test_files: []