hotel_price 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/hotel_price/agoda/agoda_scraper.rb +34 -42
- data/lib/hotel_price/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38a5082a8fd046c92eb5b3e7f68c0a51c2abdd25f5516950ef5e547296d11404
|
4
|
+
data.tar.gz: 58606a57adfe1fb211af3ab18898ab2b476a4b39e8c027cb4a1dae00073df2b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dc57df83893d7a9b0da3569ae360542939faf3560dfc4bb4a958aa196c16b8b4311deae4993fef2521fe0ec99e17e40ba1ed14f6ad9d9e66a8ab70c6b4b9b92
|
7
|
+
data.tar.gz: d1c98ae6a1afdd17b367303a080617905b94ff91b3d2b49f038f370afebf097405d98f9cab799884c90d3a48bf55c850c556b8636ab3298c9c1c520d34e163dc
|
data/Gemfile.lock
CHANGED
@@ -1,56 +1,48 @@
|
|
1
|
+
require "date"
|
2
|
+
|
1
3
|
module HotelPrice::Agoda
|
2
4
|
class AgodaScraper
|
3
|
-
def self.get_price(
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
url = "https://www.agoda.com/ja-jp/hotel-sunroute-new-sapporo/hotel/sapporo-jp.html"
|
5
|
+
def self.get_price(agoda_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.agoda.com/ja-jp/#{agoda_hotel_id}.html?#{query_string}"
|
9
10
|
driver = self.get_selenium_driver
|
10
11
|
driver.get(url)
|
11
12
|
sleep 2
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
14
|
+
data = driver.find_elements(:xpath, "//strong[@data-ppapi='room-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-selenium='hotel-header-name']").first.text
|
19
|
+
room_name = driver.find_elements(:xpath, "//span[@data-selenium='masterroom-title-name']").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}&rooms=1&travellerType=-1"
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.make_date_args checkin_date
|
31
|
+
Date.parse checkin_date rescue return ""
|
32
|
+
t = Date.parse(checkin_date)
|
33
|
+
checkin_arg = t.strftime("checkIn=%Y-%m-%d")
|
34
|
+
"#{checkin_arg}&los=2"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.make_num_adults_arg num_adults
|
38
|
+
return "" if num_adults.to_i <= 1
|
39
|
+
"adults=#{num_adults}"
|
48
40
|
end
|
49
41
|
|
50
42
|
def self.get_selenium_driver
|
51
43
|
options = Selenium::WebDriver::Firefox::Options.new
|
52
44
|
options.add_argument("-headless")
|
53
|
-
Selenium::WebDriver.for :firefox
|
45
|
+
Selenium::WebDriver.for :firefox, options: options
|
54
46
|
end
|
55
47
|
end
|
56
48
|
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.4
|
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-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|