top-travel-destinations 0.1.1

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
+ SHA1:
3
+ metadata.gz: d7985b2f3cb58c4fa15d3902d7115da84936dbe2
4
+ data.tar.gz: 2dd128675a7ab83596d304f091725a479f98cfd9
5
+ SHA512:
6
+ metadata.gz: d7d29cbaf6e29c4665109020359188f738fda5d88417e3f35158f4dd274e6b56ee133d7790a45e6470234dd2c2af9bd3ade3da1235542bb16fdb1f071ce77874
7
+ data.tar.gz: a25ed576e2f33262e7a21976c4eaf9bbdf342bd1f8459b8ff68e14477562cfe0d53ca193cc7ef206c85220e74490445fe4d0d462326f6a9f75545f6b0491a834
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../config/environment'
4
+
5
+ TopTravelDestinations::CLI.new.call
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require_relative "../lib/top_travel_destinations/version"
5
+ require_relative "../lib/top_travel_destinations/cli"
6
+ require_relative "../lib/top_travel_destinations/destination"
7
+ require_relative "../lib/top_travel_destinations/scraper"
@@ -0,0 +1,78 @@
1
+ class TopTravelDestinations::CLI
2
+
3
+ def call
4
+ create_list
5
+ list_destinations
6
+ menu
7
+ end
8
+
9
+ def create_list
10
+ TopTravelDestinations::Scraper.scrape_main_page('https://www.tripadvisor.com/TravelersChoice-Destinations-cTop-g1')
11
+ end
12
+
13
+ def add_attributes_to_destination(destination)
14
+ attributes = TopTravelDestinations::Scraper.scrape_destination_page(destination.destination_url)
15
+ destination.add_attributes(attributes)
16
+ end
17
+
18
+ def list_destinations
19
+ puts "\nTop Travel Destinations"
20
+ puts "-----------------------"
21
+ TopTravelDestinations::Destination.all.each.with_index(1) {|destination, i| puts "#{i}. #{destination.location}"}
22
+ end
23
+
24
+ def menu
25
+ input = ""
26
+ while input != "exit"
27
+ puts "\nEnter the number of the destination you'd like to know more about, type list for the original list, type display to display by continent, or exit:"
28
+ input = gets.strip.downcase
29
+
30
+ if input.to_i.between?(1, 25)
31
+ destination = TopTravelDestinations::Destination.all[input.to_i - 1]
32
+ add_attributes_to_destination(destination)
33
+ destination_details(destination)
34
+ elsif input == "display"
35
+ list_by_continent
36
+ elsif input == "list"
37
+ list_destinations
38
+ elsif input == "exit"
39
+ puts "\nThanks for using Top Travel Destinations! Safe travels.\n"
40
+ break
41
+ else
42
+ puts "\nNot sure what you mean.\n"
43
+ menu
44
+ end
45
+ end
46
+ end
47
+
48
+ def destination_details(destination)
49
+ puts "\n#{destination.location}\n"
50
+ puts "\nWhy visit?"
51
+ puts "\n#{destination.description}"
52
+ puts "http://www.visitgreece.gr/en/greek_islands/crete" if destination.description.nil?
53
+ puts "\nDon't miss:" unless destination.attractions == []
54
+ destination.attractions.each.with_index(1) {|attraction, i| puts " #{i}. #{attraction}"}
55
+ puts "\nCurrent lowest airfare: #{destination.flight_price}" unless destination.flight_price == nil
56
+ if destination.weather_high != ""
57
+ puts "\nCurrent local weather:"
58
+ puts " High: #{destination.weather_high.match(/[^°]*/)}°"
59
+ puts " Low: #{destination.weather_low.match(/[^°]*/)}°"
60
+ end
61
+ end
62
+
63
+ def list_by_continent
64
+ puts "\nAfrica, Asia, Europe, North America, South America, or Oceania?"
65
+ continent_input = gets.strip
66
+
67
+ puts "\n#{continent_input.split(" ").map {|word| word.capitalize}.join(" ")
68
+ }"
69
+ puts "----------------------------------"
70
+ destinations = TopTravelDestinations::Destination.find_by_continent(continent_input)
71
+ destinations.each do |destination|
72
+ puts "#{TopTravelDestinations::Destination.all.find_index(destination) + 1}. #{destination.location}"
73
+ end
74
+ puts "----------------------------------"
75
+ puts "*Technically, the Society Islands are not associated with a continent, but with the region of Oceania." if continent_input.downcase == "oceania"
76
+ end
77
+
78
+ end
@@ -0,0 +1,48 @@
1
+ class TopTravelDestinations::Destination
2
+ attr_accessor :location, :description, :destination_url, :attractions, :attractions_url, :flight_price, :weather_high, :weather_low
3
+
4
+ @@all = []
5
+
6
+ def initialize(destination_hash)
7
+ destination_hash.each do |attribute_name, attribute_value|
8
+ self.send("#{attribute_name}=", attribute_value)
9
+ end
10
+ save
11
+ end
12
+
13
+ def self.create_from_collection(destinations_array)
14
+ destinations_array.each {|destination| TopTravelDestinations::Destination.new(destination)}
15
+ end
16
+
17
+ def add_attributes(attributes_hash)
18
+ attributes_hash.each do |attribute_name, attribute_value|
19
+ self.send("#{attribute_name}=", attribute_value)
20
+ end
21
+ end
22
+
23
+ def self.find_by_continent(continent)
24
+ continents = {
25
+ :africa => ["Morocco"],
26
+ :asia => ["Indonesia", "Cambodia", "Thailand", "Vietnam", "Turkey", "Russia", "United Arab Emirates", "Nepal"],
27
+ :europe => ["United Kingdom", "France", "Italy", "Greece", "Spain", "Czech Republic", "Turkey", "Russia"],
28
+ :north_america => ["New York", "Jamaica", "Bay Islands", "Belize Cayes", "St. Martin", "Mexico", "Cayman Islands"],
29
+ :south_america => ["Brazil", "Peru"],
30
+ :oceania => ["Society Islands"]
31
+ }
32
+
33
+ continent_sym = continent.gsub(" ", "_").downcase.to_sym
34
+
35
+ self.all.select do |destination|
36
+ array_size = destination.location.split(/, |-/).length
37
+ continents[continent_sym].include?(destination.location.split(/, |-/)[array_size - 1])
38
+ end
39
+ end
40
+
41
+ def self.all
42
+ @@all
43
+ end
44
+
45
+ def save
46
+ self.class.all << self
47
+ end
48
+ end
@@ -0,0 +1,35 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ class TopTravelDestinations::Scraper
5
+
6
+ def self.scrape_main_page(main_page_url)
7
+ page = Nokogiri::HTML(open(main_page_url))
8
+
9
+ destinations = page.css(".mainName a").collect do |destination|
10
+ {
11
+ :location => destination.text,
12
+ :destination_url => "https://www.tripadvisor.com#{destination.attribute("href").value}"
13
+ }
14
+ end
15
+ TopTravelDestinations::Destination.create_from_collection(destinations)
16
+ end
17
+
18
+ def self.scrape_destination_page(destination_url)
19
+ page = Nokogiri::HTML(open(destination_url))
20
+ description_html = page.css("#taplc_expanding_read_more_box_0 .content")
21
+ attractions_html = page.css(".col.attractions li .name")
22
+ weather_high_html = page.css(".temps.wrap span.high")
23
+ weather_low_html = page.css(".temps.wrap span.low")
24
+ flight_price_html = page.css(".flightPrices.wrap .price")
25
+
26
+ destination_info = {
27
+ :description => (description_html.text.strip if description_html.text != ""),
28
+ :attractions => (attractions_html.collect {|a| a.text.strip} if attractions_html != []),
29
+ :weather_high => (weather_high_html.text if weather_high_html != ""),
30
+ :weather_low => (weather_low_html.text if weather_low_html != ""),
31
+ :flight_price => (flight_price_html.text.strip.match(/[$][^$]*/) if flight_price_html)
32
+ }
33
+ end
34
+
35
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: top-travel-destinations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Zenia Villa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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'
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: nokogiri
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 details on Tripadvisor's Top 25 Travel Destinations
84
+ email:
85
+ - zavilla90@gmail.com
86
+ executables:
87
+ - top-travel-destinations
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - bin/top-travel-destinations
92
+ - config/environment.rb
93
+ - lib/top_travel_destinations/cli.rb
94
+ - lib/top_travel_destinations/destination.rb
95
+ - lib/top_travel_destinations/scraper.rb
96
+ homepage: https://github.com/zeniavilla/top-travel-destinations-cli-app
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.8
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Top Travel Destinations
120
+ test_files: []