hotel_price 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +18 -3
- data/LICENSE.txt +1 -1
- data/hotel_price.gemspec +1 -0
- data/lib/hotel_price.rb +2 -0
- data/lib/hotel_price/agoda.rb +1 -1
- data/lib/hotel_price/agoda/agoda_scraper.rb +56 -0
- data/lib/hotel_price/expedia.rb +6 -0
- data/lib/hotel_price/expedia/expedia_scraper.rb +50 -0
- data/lib/hotel_price/version.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92aec7a05284637bc1bd0ccadc6f2022888e6a5392d84bca9c78c236af810393
|
4
|
+
data.tar.gz: 2154651c9955907afbb09d429766df445d24919a9cd2eaf6471911a7b8b257b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d48efbd42d28a278fce44b9af78ca1881de8fda7f966e271f3030529474f9847fe3bc053eb36279bf020ef4d7c7060f783a37b1836220e913d21b0c00814582
|
7
|
+
data.tar.gz: 79fa05cbf933589dd86918da447a776551d31f5380386d25c2a271ee39389acfef374903bedd2076d5d3b54008dae70766753917daffdb1dceb1eea0bec2211a
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,16 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hotel_price (0.3.
|
4
|
+
hotel_price (0.3.2)
|
5
|
+
activesupport (~> 6.0.2.1)
|
5
6
|
nokogiri (~> 1.10.9)
|
6
7
|
selenium-webdriver (~> 3.141)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
12
|
+
activesupport (6.0.2.1)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 0.7, < 2)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
zeitwerk (~> 2.2)
|
11
18
|
childprocess (3.0.0)
|
19
|
+
concurrent-ruby (1.1.6)
|
12
20
|
diff-lcs (1.3)
|
21
|
+
i18n (1.8.2)
|
22
|
+
concurrent-ruby (~> 1.0)
|
13
23
|
mini_portile2 (2.4.0)
|
24
|
+
minitest (5.14.0)
|
14
25
|
nokogiri (1.10.9)
|
15
26
|
mini_portile2 (~> 2.4.0)
|
16
27
|
rake (13.0.1)
|
@@ -27,10 +38,14 @@ GEM
|
|
27
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
39
|
rspec-support (~> 3.9.0)
|
29
40
|
rspec-support (3.9.0)
|
30
|
-
rubyzip (2.
|
31
|
-
selenium-webdriver (3.142.
|
41
|
+
rubyzip (2.2.0)
|
42
|
+
selenium-webdriver (3.142.7)
|
32
43
|
childprocess (>= 0.5, < 4.0)
|
33
44
|
rubyzip (>= 1.2.2)
|
45
|
+
thread_safe (0.3.6)
|
46
|
+
tzinfo (1.2.6)
|
47
|
+
thread_safe (~> 0.1)
|
48
|
+
zeitwerk (2.3.0)
|
34
49
|
|
35
50
|
PLATFORMS
|
36
51
|
ruby
|
data/LICENSE.txt
CHANGED
data/hotel_price.gemspec
CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 2.0"
|
32
32
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_runtime_dependency "activesupport", "~> 6.0.2.1"
|
34
35
|
spec.add_runtime_dependency "nokogiri", "~> 1.10.9"
|
35
36
|
spec.add_runtime_dependency "selenium-webdriver", "~> 3.141"
|
36
37
|
end
|
data/lib/hotel_price.rb
CHANGED
@@ -3,8 +3,10 @@ require "hotel_price/rakuten"
|
|
3
3
|
require "hotel_price/jalan"
|
4
4
|
require "hotel_price/agoda"
|
5
5
|
require "hotel_price/booking"
|
6
|
+
require "hotel_price/expedia"
|
6
7
|
require "selenium-webdriver"
|
7
8
|
require "net/http"
|
9
|
+
require "active_support/all"
|
8
10
|
|
9
11
|
module HotelPrice
|
10
12
|
class Error < StandardError; end
|
data/lib/hotel_price/agoda.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
module HotelPrice::Agoda
|
2
|
+
class AgodaScraper
|
3
|
+
def self.get_price(day)
|
4
|
+
datetime = DateTime.now
|
5
|
+
retr_datetime = datetime + day
|
6
|
+
date = retr_datetime.day
|
7
|
+
date_tmrw = (retr_datetime + 1).day
|
8
|
+
url = "https://www.agoda.com/ja-jp/hotel-sunroute-new-sapporo/hotel/sapporo-jp.html"
|
9
|
+
driver = self.get_selenium_driver
|
10
|
+
driver.get(url)
|
11
|
+
sleep 2
|
12
|
+
|
13
|
+
added_months = (retr_datetime.year - datetime.year) * 12 + (retr_datetime.month - datetime.month)
|
14
|
+
|
15
|
+
if added_months.positive?
|
16
|
+
(1..added_months).each do |_n|
|
17
|
+
driver.find_element(:class_name, "DayPicker-NavButton--next").click
|
18
|
+
sleep 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
today = retr_datetime.strftime("%a %b %d %Y")
|
23
|
+
tomorrow = (retr_datetime + 1).strftime("%a %b %d %Y")
|
24
|
+
|
25
|
+
driver.find_elements(:xpath, "//div[@aria-label=\"#{today}\"]")[0].click
|
26
|
+
driver.find_elements(:xpath, "//div[@aria-label=\"#{tomorrow}\"]")[0].click
|
27
|
+
driver.find_element(:xpath, "/html/body/div[14]/div/div[1]/div/div/div[5]/div/div/div/div/div/div[1]/div[1]").click
|
28
|
+
driver.find_element(:class_name, "Searchbox__searchButton__text").click
|
29
|
+
sleep 5
|
30
|
+
begin
|
31
|
+
room_name = driver.find_element(:xpath, "/html/body/div[14]/div/div[4]/div/div[2]/div/div[4]/div/div[2]/div[3]/div[1]/div[1]/div[1]/a/div/div/span").text
|
32
|
+
rescue StandardError => e
|
33
|
+
room_name = ""
|
34
|
+
end
|
35
|
+
begin
|
36
|
+
min_price = driver.find_element(:class_name, "PriceRibbon__Price").text.gsub(",", "").to_i
|
37
|
+
rescue StandardError
|
38
|
+
min_price = 0
|
39
|
+
end
|
40
|
+
sleep 3
|
41
|
+
data = {
|
42
|
+
checkin_date: datetime.year.to_s + datetime.month.to_s + date.to_i.to_s,
|
43
|
+
agoda_min_price: min_price,
|
44
|
+
agoda_min_room_name: room_name
|
45
|
+
}
|
46
|
+
puts data
|
47
|
+
driver.quit
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.get_selenium_driver
|
51
|
+
options = Selenium::WebDriver::Firefox::Options.new
|
52
|
+
options.add_argument("-headless")
|
53
|
+
Selenium::WebDriver.for :firefox#, options: options
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "date"
|
2
|
+
|
3
|
+
module HotelPrice::Expedia
|
4
|
+
class ExpediaScraper
|
5
|
+
def self.get_price(expedia_hotel_id, checkin_date, num_adults)
|
6
|
+
date = DateTime.now.strftime("%Y-%m-%d")
|
7
|
+
|
8
|
+
query_string = make_query_string(checkin_date, num_adults)
|
9
|
+
url = "https://www.expedia.co.jp/ja/#{expedia_hotel_id}.Hotel-Information?#{query_string}"
|
10
|
+
driver = self.get_selenium_driver
|
11
|
+
driver.get(url)
|
12
|
+
sleep 2
|
13
|
+
|
14
|
+
data = driver.find_elements(:xpath, "//span[@data-stid='content-hotel-lead-price']")
|
15
|
+
return { date: date, min_price: 0 } if data.empty?
|
16
|
+
price = data.first.text.delete("^0-9").to_i
|
17
|
+
|
18
|
+
hotel_name = driver.find_elements(:xpath, "//h1[@data-stid='content-hotel-title']").first.text
|
19
|
+
room_name = driver.find_elements(:xpath, "//h3[@data-stid='room-info-title-heading']").first.text
|
20
|
+
|
21
|
+
{ date: date, min_price: price, hotel_name: hotel_name, room_name: room_name }
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.make_query_string(checkin_date, num_adults)
|
25
|
+
cd_args = make_date_args checkin_date
|
26
|
+
na_args = make_num_adults_arg num_adults
|
27
|
+
"#{cd_args}&#{na_args}&x_pwa=1&rfrr=HSR&pwa_ts=1583335742618&swpToggleOn=true®ionId=3250&destination=Sapporo%2C+Hokkaido%2C+Japan&destType=MARKET&neighborhoodId=6290332&selected=5224778&sort=recommended&top_dp=5686&top_cur=JPY"
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def self.make_date_args checkin_date
|
32
|
+
Date.parse checkin_date rescue return ""
|
33
|
+
t = Date.parse(checkin_date)
|
34
|
+
checkin_arg = t.strftime("chkin=%Y-%m-%d")
|
35
|
+
checkout_arg = (t+1).strftime("chkout=%Y-%m-%d")
|
36
|
+
"#{checkin_arg}&#{checkout_arg}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.make_num_adults_arg num_adults
|
40
|
+
return "" if num_adults.to_i <= 1
|
41
|
+
"rm1=a#{num_adults}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.get_selenium_driver
|
45
|
+
options = Selenium::WebDriver::Firefox::Options.new
|
46
|
+
options.add_argument("-headless")
|
47
|
+
Selenium::WebDriver.for :firefox, options: options
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/hotel_price/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotel_price
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fumitake Kawasaki
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-03-
|
12
|
+
date: 2020-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: activesupport
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 6.0.2.1
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 6.0.2.1
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: nokogiri
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,8 +121,11 @@ files:
|
|
107
121
|
- lib/hotel_price.rb
|
108
122
|
- lib/hotel_price/agoda.rb
|
109
123
|
- lib/hotel_price/agoda/agoda_api.rb
|
124
|
+
- lib/hotel_price/agoda/agoda_scraper.rb
|
110
125
|
- lib/hotel_price/booking.rb
|
111
126
|
- lib/hotel_price/booking/booking_scraper.rb
|
127
|
+
- lib/hotel_price/expedia.rb
|
128
|
+
- lib/hotel_price/expedia/expedia_scraper.rb
|
112
129
|
- lib/hotel_price/jalan.rb
|
113
130
|
- lib/hotel_price/jalan/jalan_api.rb
|
114
131
|
- lib/hotel_price/jalan/jalan_console.rb
|