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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92aec7a05284637bc1bd0ccadc6f2022888e6a5392d84bca9c78c236af810393
4
- data.tar.gz: 2154651c9955907afbb09d429766df445d24919a9cd2eaf6471911a7b8b257b0
3
+ metadata.gz: 38a5082a8fd046c92eb5b3e7f68c0a51c2abdd25f5516950ef5e547296d11404
4
+ data.tar.gz: 58606a57adfe1fb211af3ab18898ab2b476a4b39e8c027cb4a1dae00073df2b6
5
5
  SHA512:
6
- metadata.gz: 6d48efbd42d28a278fce44b9af78ca1881de8fda7f966e271f3030529474f9847fe3bc053eb36279bf020ef4d7c7060f783a37b1836220e913d21b0c00814582
7
- data.tar.gz: 79fa05cbf933589dd86918da447a776551d31f5380386d25c2a271ee39389acfef374903bedd2076d5d3b54008dae70766753917daffdb1dceb1eea0bec2211a
6
+ metadata.gz: 6dc57df83893d7a9b0da3569ae360542939faf3560dfc4bb4a958aa196c16b8b4311deae4993fef2521fe0ec99e17e40ba1ed14f6ad9d9e66a8ab70c6b4b9b92
7
+ data.tar.gz: d1c98ae6a1afdd17b367303a080617905b94ff91b3d2b49f038f370afebf097405d98f9cab799884c90d3a48bf55c850c556b8636ab3298c9c1c520d34e163dc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotel_price (0.3.2)
4
+ hotel_price (0.3.4)
5
5
  activesupport (~> 6.0.2.1)
6
6
  nokogiri (~> 1.10.9)
7
7
  selenium-webdriver (~> 3.141)
@@ -1,56 +1,48 @@
1
+ require "date"
2
+
1
3
  module HotelPrice::Agoda
2
4
  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"
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
- 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
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#, options: options
45
+ Selenium::WebDriver.for :firefox, options: options
54
46
  end
55
47
  end
56
48
  end
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
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.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-07 00:00:00.000000000 Z
12
+ date: 2020-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler