hotel_price 0.3.6 → 0.3.7

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: 7a04503efacfaaa1ea843afd81a742852951a455ed85ddd98aa91815b2c29808
4
- data.tar.gz: c8bbd37fab7aa17d850526e2b31e4e6a151ef733507937ef5163f050c1f5cfa2
3
+ metadata.gz: a7575771cadfd2c8287586933ae0a42c57baa62718fa3a033b67e47f4624a3b3
4
+ data.tar.gz: f3ba187599e25bfcaf97b68f2821ec612830190a182c32ff50bb2ab2acd9af0b
5
5
  SHA512:
6
- metadata.gz: c589dde9e1148e0f62cc41e41d6f327fd9ec6a3afb51a7ee1f1abeb10aa7ceac66b768ba4e14b30ffbbba90169807590b25672742fde59a953647634cc4bb655
7
- data.tar.gz: cbaf4dc53eab2439a814bcf87aaee18e3653affe5d86eb386c9dcbf156d05b4f9ddc3d7edc12286d77004e39607ceff4ffc275fdbf66832cf814857b22a29fc7
6
+ metadata.gz: 609a68eba4918882cf2919298b34f9eb6fb55c57399da7ee4f2fe97cf766505a0fe7626aa5a8ad3e4cc63084a47748d593bb842ed6ae24f5df63a4981a425d2e
7
+ data.tar.gz: 762bf55a15ba7782e86d257d6a35f56dd314817922f612387725e79a12066981a6a484371a2d5d4c0f25210f00a881dfbb7a9756b87e5e54ecc1ad7d356b0c7c
@@ -195,9 +195,8 @@ Lint/UnusedMethodArgument:
195
195
  Metrics/AbcSize:
196
196
  Enabled: false
197
197
 
198
- # 6 は強すぎるので緩める
199
198
  Metrics/CyclomaticComplexity:
200
- Max: 10
199
+ Enabled: false
201
200
 
202
201
  Metrics/PerceivedComplexity:
203
202
  Enabled: false
@@ -1,15 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotel_price (0.3.4)
4
+ hotel_price (0.3.6)
5
5
  activesupport (~> 6.0.2.1)
6
+ json (~> 2.3.0)
6
7
  nokogiri (~> 1.10.9)
7
8
  selenium-webdriver (~> 3.141)
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
12
- activesupport (6.0.2.1)
13
+ activesupport (6.0.2.2)
13
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
15
  i18n (>= 0.7, < 2)
15
16
  minitest (~> 5.1)
@@ -20,6 +21,7 @@ GEM
20
21
  diff-lcs (1.3)
21
22
  i18n (1.8.2)
22
23
  concurrent-ruby (~> 1.0)
24
+ json (2.3.0)
23
25
  mini_portile2 (2.4.0)
24
26
  minitest (5.14.0)
25
27
  nokogiri (1.10.9)
@@ -38,7 +40,7 @@ GEM
38
40
  diff-lcs (>= 1.2.0, < 2.0)
39
41
  rspec-support (~> 3.9.0)
40
42
  rspec-support (3.9.0)
41
- rubyzip (2.2.0)
43
+ rubyzip (2.3.0)
42
44
  selenium-webdriver (3.142.7)
43
45
  childprocess (>= 0.5, < 4.0)
44
46
  rubyzip (>= 1.2.2)
@@ -34,4 +34,5 @@ Gem::Specification.new do |spec|
34
34
  spec.add_runtime_dependency "activesupport", "~> 6.0.2.1"
35
35
  spec.add_runtime_dependency "nokogiri", "~> 1.10.9"
36
36
  spec.add_runtime_dependency "selenium-webdriver", "~> 3.141"
37
+ spec.add_runtime_dependency "json", "~> 2.3.0"
37
38
  end
@@ -4,12 +4,22 @@ require "hotel_price/jalan"
4
4
  require "hotel_price/agoda"
5
5
  require "hotel_price/booking"
6
6
  require "hotel_price/expedia"
7
+ require "hotel_price/configuration"
7
8
  require "selenium-webdriver"
8
9
  require "net/http"
9
10
  require "active_support/all"
10
11
 
11
12
  module HotelPrice
12
13
  class Error < StandardError; end
14
+ class << self
15
+ attr_accessor :configuration
16
+ end
17
+
18
+ def self.configure
19
+ self.configuration ||= Configuration.new
20
+ yield(configuration)
21
+ end
22
+
13
23
  def self.rakuten_travel
14
24
  driver = self.get_selenium_driver
15
25
  rakuten_travel_hotel_id = 128552
@@ -36,4 +46,14 @@ module HotelPrice
36
46
  options.add_argument("-headless")
37
47
  Selenium::WebDriver.for :firefox, options: options
38
48
  end
49
+
50
+ class Configuration
51
+ # Agoda API key
52
+ # @param [String]
53
+ attr_accessor :agoda_api_key
54
+
55
+ def initialize
56
+ @agoda_api_key = nil
57
+ end
58
+ end
39
59
  end
@@ -1,36 +1,39 @@
1
+ require 'json'
2
+
1
3
  module HotelPrice::Agoda
2
4
  class AgodaAPI
3
- def initialize api_key
4
- @api_key = api_key
5
- end
6
- def test
5
+ def self.get_price(hotel_id, checkin_date, num_adults)
6
+ @api_key = HotelPrice.configuration ? HotelPrice.configuration.agoda_api_key : nil
7
+ if @api_key.nil?
8
+ puts "Must specify agoda_api_key in configuration to use the Agoda API"
9
+ return -1
10
+ end
11
+
7
12
  endpoint_url = "http://affiliateapi7643.agoda.com/affiliateservice/lt_v1"
8
13
  # 検索条件の指定
9
14
  # cityId, checkInDate, checkOutDate は必須、ソレ以外はオプション。
15
+ #
16
+ checkin_date = checkin_date.to_s
17
+ Date.parse checkin_date rescue return ""
18
+ t = Date.parse(checkin_date)
19
+ checkin_arg = t.strftime("%Y-%m-%d")
20
+ checkout_arg = (t + 1).strftime("%Y-%m-%d")
21
+
10
22
  params = {
11
- "criteria": {
12
- "additional": {
13
- "currency": "JPY",
14
- "dailyRate": {
15
- "maximum": 100000,
16
- "minimum": 1000
17
- },
18
- "discountOnly": false,
19
- "language": "ja-jp",
20
- "maxResult": 10,
21
- "minimumReviewScore": 0,
22
- "minimumStarRating": 0,
23
- "occupancy": {
24
- "numberOfAdult": 1,
25
- "numberOfChildren": 0
26
- },
27
- "sortBy": "PriceAsc"
28
- },
29
- "discountOnly": true,
30
- "checkInDate": "2020-10-02",
31
- "checkOutDate": "2020-10-03",
32
- "cityId": 5235
33
- }
23
+ "criteria": {
24
+ "additional": {
25
+ "currency": "JPY",
26
+ "discountOnly": false,
27
+ "language": "ja-jp",
28
+ "occupancy": {
29
+ "numberOfAdult": num_adults,
30
+ "numberOfChildren": 0
31
+ }
32
+ },
33
+ "checkInDate": checkin_arg,
34
+ "checkOutDate": checkout_arg,
35
+ "hotelId": [hotel_id]
36
+ }
34
37
  }
35
38
 
36
39
  url = URI.parse(endpoint_url)
@@ -42,7 +45,11 @@ module HotelPrice::Agoda
42
45
  http.request(req)
43
46
  end
44
47
 
45
- puts res.body
48
+ parsed_body = JSON.parse(res.body)
49
+ if parsed_body['results'].nil? || parsed_body['results'].empty?
50
+ return "No rooms for search criteria - please confirm hotel ID"
51
+ end
52
+ parsed_body['results'][0]['dailyRate']
46
53
  end
47
54
  end
48
55
  end
@@ -5,7 +5,7 @@ module HotelPrice::Agoda
5
5
  def self.get_price(agoda_hotel_id, checkin_date, num_adults)
6
6
  date = DateTime.now.strftime("%Y-%m-%d")
7
7
 
8
- query_string = make_query_string(checkin_date, num_adults)
8
+ query_string = make_query_string(checkin_date.to_s, num_adults)
9
9
  url = "https://www.agoda.com/ja-jp/#{agoda_hotel_id}.html?#{query_string}"
10
10
  driver = self.get_selenium_driver
11
11
  driver.get(url)
@@ -15,8 +15,13 @@ module HotelPrice::Agoda
15
15
  return { date: date, min_price: 0 } if data.empty?
16
16
  price = data.first.text.delete("^0-9").to_i
17
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
18
+ hotel_name = ""
19
+ room_name = ""
20
+
21
+ hotel_name_element = driver.find_elements(:xpath, "//h1[@data-selenium='hotel-header-name']")
22
+ hotel_name = hotel_name_element.first.text unless hotel_name_element.empty?
23
+ room_name_element = driver.find_elements(:xpath, "//span[@data-selenium='masterroom-title-name']")
24
+ room_name = room_name_element.first.text unless room_name_element.empty?
20
25
 
21
26
  { date: date, min_price: price, hotel_name: hotel_name, room_name: room_name }
22
27
  end
@@ -5,7 +5,7 @@ module HotelPrice::Booking
5
5
  def self.get_price(booking_hotel_id, checkin_date, num_adults)
6
6
  date = DateTime.now.strftime("%Y-%m-%d")
7
7
 
8
- query_string = make_query_string(checkin_date, num_adults)
8
+ query_string = make_query_string(checkin_date.to_s, num_adults)
9
9
  url = "https://www.booking.com/hotel/jp/#{booking_hotel_id}.ja.html?#{query_string}"
10
10
  driver = self.get_selenium_driver
11
11
  driver.get(url)
@@ -17,8 +17,13 @@ module HotelPrice::Booking
17
17
  return { date: date, min_price: 0 } if price_box.empty?
18
18
  price = price_box.first.text.delete("^0-9").to_i
19
19
 
20
- hotel_name = driver.find_elements(:class_name, "hp__hotel-type-badge").first.text
21
- room_name = driver.find_elements(:class_name, "hprt-ws-roomtype-link").first.text
20
+ hotel_name = ""
21
+ room_name = ""
22
+
23
+ hotel_name_element = driver.find_elements(:class_name, "hp__hotel-type-badge")
24
+ hotel_name = hotel_name_element.first.text unless hotel_name_element.empty?
25
+ room_name_element = driver.find_elements(:class_name, "hprt-ws-roomtype-link")
26
+ room_name = room_name_element.first.text unless room_name_element.empty?
22
27
 
23
28
  { date: date, min_price: price, hotel_name: hotel_name, room_name: room_name }
24
29
  end
File without changes
@@ -5,7 +5,7 @@ module HotelPrice::Expedia
5
5
  def self.get_price(expedia_hotel_id, checkin_date, num_adults)
6
6
  date = DateTime.now.strftime("%Y-%m-%d")
7
7
 
8
- query_string = make_query_string(checkin_date, num_adults)
8
+ query_string = make_query_string(checkin_date.to_s, num_adults)
9
9
  url = "https://www.expedia.co.jp/ja/#{expedia_hotel_id}.Hotel-Information?#{query_string}"
10
10
  driver = self.get_selenium_driver
11
11
  driver.get(url)
@@ -15,8 +15,13 @@ module HotelPrice::Expedia
15
15
  return { date: date, min_price: 0 } if data.empty?
16
16
  price = data.first.text.delete("^0-9").to_i
17
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
18
+ hotel_name = ""
19
+ room_name = ""
20
+
21
+ hotel_name_element = driver.find_elements(:xpath, "//h1[@data-stid='content-hotel-title']")
22
+ hotel_name = hotel_name_element.first.text unless hotel_name_element.empty?
23
+ room_name_element = driver.find_elements(:xpath, "//h3[@data-stid='room-info-title-heading']")
24
+ room_name = room_name_element.first.text unless room_name_element.empty?
20
25
 
21
26
  { date: date, min_price: price, hotel_name: hotel_name, room_name: room_name }
22
27
  end
@@ -7,6 +7,44 @@ module HotelPrice::Rakuten
7
7
  }
8
8
  end
9
9
 
10
+ def get_price(rakuten_hotel_id, checkin_date, num_adults)
11
+ query_string = make_query_string(rakuten_hotel_id, checkin_date.to_s, num_adults)
12
+ url = "https://app.rakuten.co.jp/services/api/Travel/VacantHotelSearch/20131024?#{query_string}"
13
+ json = Net::HTTP.get(URI.parse(url))
14
+ result = JSON.parse(json)
15
+ if result["error"] == "not_found"
16
+ {
17
+ date: DateTime.now.strftime("%Y-%m-%d"),
18
+ checkin_date: params[:checkin_date],
19
+ rakuten_hotel_id: params[:rakuten_hotel_id],
20
+ adult_num: params[:adult_num],
21
+ breakfast: params[:breakfast],
22
+ plan_num: 0,
23
+ min_price: 0
24
+ }
25
+ elsif result["error"] == "wrong_parameterd"
26
+ "入力した値が正しくありません。"
27
+ else
28
+ {
29
+ date: DateTime.now.strftime("%Y-%m-%d"),
30
+ checkin_date: result["hotels"][0]["hotel"][1]["roomInfo"][1]["dailyCharge"]["stayDate"],
31
+ rakuten_hotel_id: params[:rakuten_hotel_id],
32
+ hotel_name: result["hotels"][0]["hotel"][0]["hotelBasicInfo"]["hotelName"],
33
+ adult_num: params[:adult_num],
34
+ breakfast: params[:breakfast],
35
+ plan_num: result["pagingInfo"]["recordCount"],
36
+ room_name: result["hotels"][0]["hotel"][1]["roomInfo"][0]["roomBasicInfo"]["roomName"],
37
+ plan_name: result["hotels"][0]["hotel"][1]["roomInfo"][0]["roomBasicInfo"]["planName"],
38
+ min_price: result["hotels"][0]["hotel"][1]["roomInfo"][1]["dailyCharge"]["rakutenCharge"]
39
+ }
40
+ end
41
+ end
42
+
43
+ def make_query_string(rakuten_hotel_id, checkin_date, num_adults)
44
+ checkout_date = (Date.parse(checkin_date) + 2).strftime("%Y-%m-%d")
45
+ "format=json&sort=%2BroomCharge&searchPattern=1&applicationId=#{@config[:rakuten_api_key]}&adultNum=#{num_adults}&checkinDate=#{checkin_date}&checkoutDate=#{checkout_date}&squeezeCondition="
46
+ end
47
+
10
48
  def get_min_price params
11
49
  params[:breakfast] ||= ""
12
50
  try = 0
@@ -60,12 +98,12 @@ module HotelPrice::Rakuten
60
98
  def hotel_info
61
99
  uri = URI.parse("https://app.rakuten.co.jp/services/api/Travel/HotelDetailSearch/20131024?hotelNo=" + @config[:rakuten_hotel_id].to_s + "&applicationId=" + @config[:rakuten_api_key].to_s + "&datumType=1&responseType=large")
62
100
  json = Net::HTTP.get(uri)
63
- @result = JSON.parse(json)
64
- return "ホテル情報がありませんでした。" if @result["error"] == "not_found"
65
- return @result["error_description"] if @result["error"] == "wrong_parameter"
66
- @result["hotels"][0].each do |_key, field|
101
+ result = JSON.parse(json)
102
+ return "ホテル情報がありませんでした。" if result["error"] == "not_found"
103
+ return result["error_description"] if result["error"] == "wrong_parameter"
104
+ result["hotels"][0].each do |_key, field|
67
105
  field[0].each do |_, value|
68
- @data_hash = {
106
+ data_hash = {
69
107
  rakuten_hotel_id: value["hotelNo"],
70
108
  hotel_name: value["hotelName"],
71
109
  room_price_min: value["hotelMinCharge"],
@@ -85,44 +123,44 @@ module HotelPrice::Rakuten
85
123
  }
86
124
  end
87
125
  end
88
- @result["hotels"][0].each do |_key, field|
126
+ result["hotels"][0].each do |_key, field|
89
127
  field[1].each do |_, value|
90
- @data_hash["rakuten_service_review"] = value["serviceAverage"].to_f
91
- @data_hash["rakuten_location_review"] = value["locationAverage"].to_f
92
- @data_hash["rakuten_room_review"] = value["roomAverage"].to_f
93
- @data_hash["rakuten_equipment_review"] = value["equipmentAverage"].to_f
94
- @data_hash["rakuten_bath_review"] = value["bathAverage"].to_f
95
- @data_hash["rakuten_meal_review"] = value["mealAverage"].to_f
128
+ data_hash["rakuten_service_review"] = value["serviceAverage"].to_f
129
+ data_hash["rakuten_location_review"] = value["locationAverage"].to_f
130
+ data_hash["rakuten_room_review"] = value["roomAverage"].to_f
131
+ data_hash["rakuten_equipment_review"] = value["equipmentAverage"].to_f
132
+ data_hash["rakuten_bath_review"] = value["bathAverage"].to_f
133
+ data_hash["rakuten_meal_review"] = value["mealAverage"].to_f
96
134
  end
97
135
  end
98
- @result["hotels"][0].each do |_key, field|
136
+ result["hotels"][0].each do |_key, field|
99
137
  field[2].each do |_, value|
100
- @data_hash["middle_class_code"] = value["middleClassCode"].to_s
101
- @data_hash["small_class_code"] = value["smallClassCode"].to_s
102
- @data_hash["area_name"] = value["areaName"].to_s
103
- @data_hash["hotel_class_code"] = value["hotelClassCode"].to_s
104
- @data_hash["checkin_time"] = value["checkinTime"].to_s
105
- @data_hash["checkout_time"] = value["checkoutTime"].to_s
106
- @data_hash["last_checkin_time"] = value["lastCheckinTime"].to_s
138
+ data_hash["middle_class_code"] = value["middleClassCode"].to_s
139
+ data_hash["small_class_code"] = value["smallClassCode"].to_s
140
+ data_hash["area_name"] = value["areaName"].to_s
141
+ data_hash["hotel_class_code"] = value["hotelClassCode"].to_s
142
+ data_hash["checkin_time"] = value["checkinTime"].to_s
143
+ data_hash["checkout_time"] = value["checkoutTime"].to_s
144
+ data_hash["last_checkin_time"] = value["lastCheckinTime"].to_s
107
145
  end
108
146
  end
109
- @result["hotels"][0].each do |_key, field|
147
+ result["hotels"][0].each do |_key, field|
110
148
  field[3].each do |_, value|
111
- @data_hash["total_room_num"] = value["hotelRoomNum"].to_s
149
+ data_hash["total_room_num"] = value["hotelRoomNum"].to_s
112
150
  room_facilities = []
113
151
  value["roomFacilities"].each_with_index do |f, i|
114
152
  room_facilities[i] = f["item"]
115
153
  end
116
- @data_hash["room_facilities"] = room_facilities
154
+ data_hash["room_facilities"] = room_facilities
117
155
  end
118
156
  end
119
- @result["hotels"][0].each do |_key, field|
157
+ result["hotels"][0].each do |_key, field|
120
158
  field[4].each do |_, value|
121
- @data_hash["hotel_policy_note"] = value["note"].to_s
122
- @data_hash["cancel_policy"] = value["cancelPolicy"].to_s
159
+ data_hash["hotel_policy_note"] = value["note"].to_s
160
+ data_hash["cancel_policy"] = value["cancelPolicy"].to_s
123
161
  end
124
162
  end
125
- @data_hash
163
+ data_hash
126
164
  end
127
165
  end
128
166
  end
@@ -7,6 +7,541 @@ module HotelPrice::Rakuten
7
7
  chain: params[:chain] ||= false,
8
8
  rakuten_hotel_id: params[:rakuten_hotel_id] ||= 0
9
9
  }
10
+ options = Selenium::WebDriver::Firefox::Options.new
11
+ options.add_argument("-headless")
12
+ @wait = Selenium::WebDriver::Wait.new(:timeout => 100)
13
+ @driver = Selenium::WebDriver.for :firefox#, options: options
14
+ if @config[:chain]
15
+ go_to_management_page_chain
16
+ else
17
+ go_to_management_page_single
18
+ end
19
+ end
20
+
21
+ def go_to_management_page_chain
22
+ @driver.get "https://manage.travel.rakuten.co.jp/portal/inn/ry_group.main"
23
+ @driver.find_element(:name, "f_id").send_keys @config[:login_id].to_s
24
+ @driver.find_element(:name, "f_pass").send_keys @config[:login_pw].to_s
25
+ @driver.find_element(:xpath, "/html/body/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td/form/table/tbody/tr[2]/td[3]/input").click
26
+ begin
27
+ @driver.find_element(:xpath, "/html/body/center/table/tbody/tr[5]/td[2]/form[3]/input[8]").click
28
+ rescue StandardError
29
+ @driver.find_element(:xpath, "/html/body/center/table/tbody/tr[7]/td[2]/form[3]/input[8]").click
30
+ end
31
+ @i = 0
32
+ (2..21).each do |i|
33
+ rakuten_hotel_id = @driver.find_element(:xpath, "/html/body/center[2]/table/tbody/tr[#{i}]/td[1]").text
34
+ @i = i if @config[:rakuten_hotel_id].to_s == rakuten_hotel_id.to_s
35
+ break if @i == i
36
+ end
37
+ until @i != 0
38
+ @driver.find_element(:xpath, "/html/body/table/tbody/tr/td[2]/form/input[10]").click
39
+ (2..21).each do |i|
40
+ rakuten_hotel_id = @driver.find_element(:xpath, "/html/body/center[2]/table/tbody/tr[#{i}]/td[1]").text
41
+ @i = i if @config[:rakuten_hotel_id].to_s == rakuten_hotel_id.to_s
42
+ break if @i == i
43
+ end
44
+ end
45
+ @driver.find_element(:xpath, "/html/body/center[2]/table/tbody/tr[#{@i}]/td[3]/form/input[10]").click
46
+ @driver
47
+ end
48
+
49
+ def go_to_management_page_single
50
+ @driver.get "https://manage.travel.rakuten.co.jp/portal/inn/mp_kanri_image_up.main"
51
+ @driver.find_element(:name, "f_id").send_keys @config[:login_id]
52
+ @driver.find_element(:name, "f_pass").send_keys @config[:login_pw]
53
+ @driver.find_element(:xpath, "/html/body/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td/form/table/tbody/tr[2]/td[3]/input").click
54
+ @driver
55
+ end
56
+
57
+ def go_to_plan_setting
58
+ @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[3]/tbody/tr[2]/td[1]/table/tbody/tr[3]/td/table/tbody/tr[1]/td[2]/input").click
59
+ @wait.until { @driver.find_element(:link_text, "宿泊プラン") }
60
+ @driver.find_element(:link_text, "宿泊プラン").click
61
+ @plans = @driver.find_elements(:class, "h_top_pl_name")
62
+ @driver
63
+ end
64
+
65
+ def get_plan_num
66
+ go_to_plan_setting
67
+ @driver.quit
68
+ @plans.size
69
+ end
70
+
71
+ def save_plan_name
72
+ go_to_plan_setting
73
+ @data = {}
74
+ @plans.each_with_index do |row, i|
75
+ cells = row.find_elements(:css, "td")
76
+ plan_info = row.text.split(":")
77
+ @data[i] = {
78
+ hotel_id: @hotel.id,
79
+ manage_number: plan_info[0],
80
+ plan_name: plan_info[1]
81
+ }
82
+ puts "saved" if RakutenPlan.create(@data[i]).valid?
83
+ end
84
+ @driver.quit
85
+ end
86
+
87
+ def edit_plan
88
+ go_to_plan_setting
89
+ @data = {}
90
+ @plans.each_with_index do |row, i|
91
+ cells = row.find_elements(:css, "td")
92
+ plan_info = row.text.split(":")
93
+ @data[i] = {
94
+ hotel_id: @hotel.id,
95
+ manage_number: plan_info[0],
96
+ plan_name: plan_info[1]
97
+ }
98
+ end
99
+
100
+ (0..@plans.size - 1).each do |i|
101
+ plan = RakutenPlan.find_by(manage_number: @data[i][:manage_number])
102
+ @driver.find_element(:link_text, @data[i][:plan_name]).click
103
+ status = @driver.find_element(:xpath, "/html/body/form[4]/table[1]/tbody/tr/td/table/tbody[1]/tr[3]/td[2]").text
104
+ flag = []
105
+ flag[0] = "楽天トラベル[宿泊のみ]" if @driver.find_element(:name, "f_tabi_flg").selected?
106
+
107
+ if @driver.find_element(:name, "f_dp_del_flg").selected?
108
+ flag[1] = "ANA楽パック" if @driver.find_element(:name, "f_dp_ana_flg").selected?
109
+ flag[2] = "JAL楽パック" if @driver.find_element(:name, "f_dp_jal_flg").selected?
110
+ end
111
+ flag[3] = "R-with" if @driver.find_element(:name, "f_kobetu_flg").selected?
112
+ begin
113
+ plan_name_p = @driver.find_element(:name, "f_dp_title").attribute("value")
114
+ plan_body_p = @driver.find_element(:name, "f_dp_naiyo").attribute("value")
115
+
116
+ plan_name_r = @driver.find_element(:name, "f_rw_title").attribute("value")
117
+ plan_body_r = @driver.find_element(:name, "f_rw_naiyo").attribute("value")
118
+ rescue StandardError => e
119
+ plan_name_p = ""
120
+ plan_body_p = ""
121
+
122
+ plan_name_r = ""
123
+ plan_body_r = ""
124
+ puts "no dp"
125
+ puts e
126
+ end
127
+
128
+ plan_body = @driver.find_element(:name, "f_naiyo").attribute("value")
129
+
130
+ # inbound = @driver.find_element(:xpath, "/html/body/form[4]/table[1]/tbody/tr/td/table/tbody[1]/tr[11]/td[2]/table/tbody/tr[1]/td/label") if @driver.find_element(:name, "f_multi").selected?
131
+ @room_types = @driver.find_elements(:name, "f_syu")
132
+ @room_type = []
133
+ @room_types.each_with_index do |row, i|
134
+ if row.selected?
135
+ @room_type[i - 1] = row.attribute("value")
136
+ end
137
+ end
138
+ plan_start_y = @driver.find_element(:name, "f_k_nen1").attribute("value")
139
+ plan_start_m = @driver.find_element(:name, "f_k_tuki1").attribute("value")
140
+ plan_start_d = @driver.find_element(:name, "f_k_hi1").attribute("value")
141
+ plan_end_y = @driver.find_element(:name, "f_k_nen2").attribute("value")
142
+ plan_end_m = @driver.find_element(:name, "f_k_tuki2").attribute("value")
143
+ plan_end_d = @driver.find_element(:name, "f_k_hi2").attribute("value")
144
+ stay_start_y = @driver.find_element(:name, "f_nen1").attribute("value")
145
+ stay_start_m = @driver.find_element(:name, "f_tuki1").attribute("value")
146
+ stay_start_d = @driver.find_element(:name, "f_hi1").attribute("value")
147
+ stay_end_y = @driver.find_element(:name, "f_nen2").attribute("value")
148
+ stay_end_m = @driver.find_element(:name, "f_tuki2").attribute("value")
149
+ stay_end_d = @driver.find_element(:name, "f_hi2").attribute("value")
150
+ min_stay = @driver.find_element(:name, "f_min_hak").attribute("value")
151
+ max_stay = @driver.find_element(:name, "f_max_hak").attribute("value")
152
+ checkintime = @driver.find_element(:name, "f_lt_plan_in").attribute("value")
153
+ checkouttime = @driver.find_element(:name, "f_lt_plan_in_limit").attribute("value")
154
+
155
+ @driver.find_elements(:name, "f_credit").each_with_index do |f, i|
156
+ next unless f.selected?
157
+
158
+ @payment_method = if i == 0
159
+ "現金決済または事前カード決済"
160
+ elsif i == 1
161
+ "事前カード決済のみ"
162
+ elsif i == 2
163
+ "現金のみ"
164
+ else
165
+ ""
166
+ end
167
+ end
168
+
169
+ plan_hash = {
170
+ plan_name_p: plan_name_p,
171
+ plan_name_r: plan_name_r,
172
+ plan_body: plan_body.gsub("\n", ""),
173
+ plan_body_p: plan_body_p.gsub("\n", ""),
174
+ plan_body_r: plan_body_r.gsub("\n", ""),
175
+ # :inbound => inbound,
176
+ room_type_ids: @room_type,
177
+ plan_start: plan_start_y + "-" + plan_start_m + "-" + plan_start_d,
178
+ plan_end: plan_end_y + "-" + plan_end_m + "-" + plan_end_d,
179
+ stay_start: stay_start_y + "-" + stay_start_m + "-" + stay_start_d,
180
+ stay_end: stay_end_y + "-" + stay_end_m + "-" + stay_end_d,
181
+ payment_method: @payment_method,
182
+ min_stay: min_stay,
183
+ max_stay: max_stay,
184
+ checkintime: checkintime,
185
+ checkouttime: checkouttime
186
+ }
187
+ puts "plan saved!: #{plan_hash}" if plan.update_attributes(plan_hash)
188
+ @driver.navigate.back
189
+ end
190
+
191
+ @driver.quit
192
+ end
193
+
194
+ def save_room_type
195
+ @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[3]/tbody/tr[2]/td[1]/table/tbody/tr[3]/td/table/tbody/tr[1]/td[2]/input").click
196
+ @wait.until { @driver.find_element(:link_text, "宿泊") }
197
+ @driver.find_element(:link_text, "宿泊").click
198
+ @room_types = @driver.find_elements(:class, "h_top_rm_name")
199
+ @data = {}
200
+ @room_types.each_with_index do |row, i|
201
+ cells = row.find_elements(:css, "td")
202
+ room_type_info = row.text.split(":")
203
+ @data[i] = {
204
+ hotel_id: @hotel.id,
205
+ room_type_id: room_type_info[0],
206
+ room_type_name: room_type_info[1]
207
+ }
208
+ puts "saved" if RakutenRoom.create(@data[i]).valid?
209
+ end
210
+ @driver.quit
211
+ end
212
+
213
+ def edit_room_type
214
+ @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[3]/tbody/tr[2]/td[1]/table/tbody/tr[3]/td/table/tbody/tr[1]/td[2]/input").click
215
+ @wait.until { @driver.find_element(:link_text, "宿泊") }
216
+ @driver.find_element(:link_text, "宿泊").click
217
+ @room_types = @driver.find_elements(:class, "h_top_rm_name")
218
+ @data = {}
219
+ @room_types.each_with_index do |row, i|
220
+ cells = row.find_elements(:css, "td")
221
+ room_type_info = row.text.split(":")
222
+ @data[i] = {
223
+ hotel_id: @hotel.id,
224
+ room_type_id: room_type_info[0],
225
+ room_type_name: room_type_info[1]
226
+ }
227
+ end
228
+ (0..@data.size - 1).each do |room_types|
229
+ @driver.find_element(:link_text, @data[room_types][:room_type_name]).click
230
+ flag = []
231
+ flag[0] = "楽天トラベル[宿泊のみ]" if @driver.find_element(:name, "f_tabimado_del_flg").selected?
232
+
233
+ if @driver.find_element(:name, "f_dp_del_flg").selected?
234
+ flag[1] = "楽天トラベルパッケージ"
235
+ room_type_name_p = @driver.find_element(:name, "f_n_dp_syu").attribute("value")
236
+ remark_p = @driver.find_element(:name, "f_r_dp_syu").attribute("value")
237
+ else
238
+ room_type_name_p = ""
239
+ remark_p = ""
240
+ end
241
+ flag[2] = "R-with" if @driver.find_element(:name, "f_kobetu_del_flg").selected?
242
+ flag[3] = "R-with[割引料金]" if @driver.find_element(:name, "f_vip_del_flg").selected?
243
+
244
+ room_facility = []
245
+ room_facility[0] = "トイレ" if @driver.find_element(:id, "view4_toilet") .selected?
246
+ room_facility[1] = "バス" if @driver.find_element(:id, "view4_bath") .selected?
247
+ room_facility[2] = "シャワーのみ" if @driver.find_element(:id, "view4_shower") .selected?
248
+ img_url = @driver.find_element(:name, "f_img_url").attribute("value")
249
+ @driver.find_elements(:name, "f_pic_flg").each do |f|
250
+ img_url = if f.selected?
251
+ @driver.find_element(:name, "f_img_url").attribute("value")
252
+ else
253
+ ""
254
+ end
255
+ end
256
+
257
+ @driver.find_elements(:name, "f_credit").each_with_index do |f, i|
258
+ next unless f.selected?
259
+
260
+ @payment_method = if i == 0
261
+ "現金決済または事前カード決済"
262
+ elsif i == 1
263
+ "事前カード決済のみ"
264
+ elsif i == 2
265
+ "現金のみ"
266
+ else
267
+ ""
268
+ end
269
+ end
270
+
271
+ if @driver.find_element(:id, "nc_width1").selected?
272
+ mm = @driver.find_element(:id, "su_width1").attribute("value")
273
+ room_size = mm.to_s + "㎡"
274
+ room_size_mm = mm.to_i
275
+ room_size_tatami = ""
276
+ elsif @driver.find_element(:id, "nc_width2").selected?
277
+ mm = @driver.find_element(:id, "nc_width2").attribute("value")
278
+ room_size = mm.to_s + "畳"
279
+ room_size_mm = ""
280
+ room_size_tatami = mm.to_i
281
+ elsif @driver.find_element(:id, "nc_width3").selected?
282
+ room_size = "客室により異なる"
283
+ room_size_mm = ""
284
+ room_size_tatami = ""
285
+ end
286
+ (0..5).each do |i|
287
+ room_category = @driver.find_element(:id, "view2_type_#{i}").attribute("value") if @driver.find_element(:id, "view2_type_#{i}").selected?
288
+ end
289
+
290
+ # Pause sort
291
+ # room_facility = %w(禁煙ルーム 喫煙ルーム インターネットができる部屋 露天風呂付き客室 ジャグジーのある客室 離れ客室 コーナールーム 二間以上 洗浄機付きトイレ 高層階 夜景が見える 海が見える 山が見える 湖が見える 川が見える)
292
+ # sort = []
293
+ # for i in 1 .. 13
294
+ # sort[i-1] = room_facility[i-1] if @driver.find_element(:id, "narrow#{i}").selected?
295
+ # end
296
+ # sort.compact!
297
+
298
+ room_db = RakutenRoom.find_by(hotel_id: @hotel.id, room_type_id: @data[room_types][:room_type_id])
299
+ room_type_data = {
300
+ public: flag,
301
+ room_type_name_p: room_type_name_p,
302
+ capacity_min: @driver.find_element(:xpath, "/html/body/table[8]/tbody/tr/td/table[1]/tbody/tr[5]/td[2]").text.gsub(" 名~ 名", ""),
303
+ capacity_max: @driver.find_element(:name, "f_max").attribute("value"),
304
+ remark: @driver.find_element(:name, "f_bikou").attribute("value"),
305
+ remark_p: remark_p,
306
+ room_size: room_size,
307
+ room_size_mm: room_size_mm,
308
+ room_size_tatami: room_size_tatami,
309
+ room_category: room_category,
310
+ room_facility: room_facility,
311
+ room_img: img_url,
312
+ #:sort => sort,
313
+ payment_method: @payment_method
314
+ }
315
+ puts "room type info updated: #{@hotel.id}" if room_db.update_attributes(room_type_data)
316
+ @driver.navigate.back
317
+ end
318
+ @driver.quit
319
+ end
320
+
321
+ def login_check
322
+ exp = @driver.find_element(:xpath, "/html/body/table[1]/tbody/tr[1]/td/table/tbody/tr/td[5]/table/tbody/tr[1]/td").text.gsub("次回パスワード更新日:", "").gsub("※事前にパスワードを変更されたい場合はこちらをご参照ください。\n", "")
323
+ rakuten_hotel_id = @driver.find_element(:xpath, "/html/body/table[1]/tbody/tr[1]/td/table/tbody/tr/td[2]/table/tbody/tr/td").text.gsub("施設番号 : ", "").split("\n")[0]
324
+ @driver.quit
325
+ {
326
+ status: "success",
327
+ password_exp_date: exp,
328
+ rakuten_hotel_id: rakuten_hotel_id
329
+ }
330
+ rescue => e
331
+ @driver.quit
332
+ {
333
+ status: "error",
334
+ error: e.to_s
335
+ }
336
+ end
337
+
338
+ def get_area_seo_rank
339
+ ranking_page = @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[1]/tbody/tr[2]/td/table/tbody/tr[1]/td[5]/table/tbody/tr/td/table[1]/tbody/tr[5]/td[2]/font/b")
340
+ rows = @driver.find_elements(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[1]/tbody/tr[2]/td/table/tbody/tr[1]/td[5]/table/tbody/tr/td/table[1]/tbody/tr[5]")
341
+ rows.each do |f|
342
+ cells = f.find_elements(:css, "td").map(&:text)
343
+ return cells[1]
344
+ end
345
+ end
346
+
347
+ def degit2 num
348
+ num = "0#{num}" if num.to_s.size == 1
349
+ num
350
+ end
351
+
352
+ def get_reservation_info
353
+ t = Time.now
354
+ management_page = @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[3]/tbody/tr[2]/td[2]/table/tbody/tr[3]/td/input").click
355
+ if t.day == 1
356
+ last_month = degit2 t.prev_month.month.to_i
357
+ yesterday = degit2 t.prev_month.end_of_month.day.to_i
358
+ this_month = degit2 t.month.to_i
359
+ today = degit2 t.day.to_i
360
+ last_month_select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_tuki1"))
361
+ last_month_select.select_by(:value, last_month.to_s)
362
+ yesterday_select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_hi1"))
363
+ yesterday_select.select_by(:value, yesterday.to_s)
364
+ this_month_select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_tuki2"))
365
+ this_month_select.select_by(:value, this_month.to_s)
366
+ today_select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_hi2"))
367
+ today_select.select_by(:value, today.to_s)
368
+ search = @driver.find_element(:xpath, "/html/body/table[7]/tbody/tr[1]/td[4]/input").click
369
+ else
370
+ yesterday = degit2 t.yesterday.day.to_i
371
+ today = degit2 t.day.to_i
372
+ yesterday_select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_hi1"))
373
+ yesterday_select.select_by(:value, yesterday.to_s)
374
+ today_select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_hi2"))
375
+ today_select.select_by(:value, today.to_s)
376
+ search = @driver.find_element(:xpath, "/html/body/table[7]/tbody/tr[1]/td[4]/input").click
377
+ end
378
+
379
+ @wait.until { @driver.find_elements(:xpath, "//tr") }
380
+ sleep 10
381
+ rows = @driver.find_elements(:xpath, "//tr")
382
+ row_num = rows.size
383
+ if row_num != 25
384
+ rows[21..row_num - 4].each do |row|
385
+ cells = row.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
386
+ point = cells[4].split("\n")[3].gsub("予定ポイント:", "").gsub(" ポイント", "") if cells[4].split("\n")[3].present?
387
+ begin
388
+ if cells[0].size < 7
389
+ @reservation_date = {
390
+ date: Time.now.strftime("%F"),
391
+ reservation_status: cells[0],
392
+ reservation_date: cells[1].split("\n")[2],
393
+ checkindate: cells[1].split("\n")[0],
394
+ checkoutdate: cells[1].split("\n")[1],
395
+ room_type: cells[2].split("\n")[0],
396
+ reservation_number: cells[2].split("\n")[2].split(":")[1],
397
+ payment_on_cash: cells[3].gsub("円", "").to_i,
398
+ price: cells[2].split("\n")[1].split(":")[0].gsub("円人数", ""),
399
+ guest_name: cells[4].split("\n")[0],
400
+ guest_tel: cells[4].split("\n")[1].gsub("(", "").gsub(")", ""),
401
+ point: point
402
+ }
403
+ else
404
+ plan_number = cells[2].split("\n")[0].scan(/\(.+?\)/).last
405
+ @reservation_date = {
406
+ date: Time.now.strftime("%F"),
407
+ hotel_id: @hotel.id,
408
+ reservation_status: cells[0].split("\n\n")[1],
409
+ reservation_date: cells[1].split("\n")[2],
410
+ checkindate: cells[1].split("\n")[0],
411
+ checkoutdate: cells[1].split("\n")[1],
412
+ plan_name: cells[2].split("\n")[0],
413
+ plan_number: plan_number.to_s.gsub("(", "").gsub(")", ""),
414
+ room_type: cells[2].split("\n")[1],
415
+ price: cells[2].split("\n")[2].split(":")[0].gsub("円人数", ""),
416
+ ppl_num: cells[2].split("\n")[2].split(":")[1].gsub("(", "").gsub(")", ""),
417
+ reservation_number: cells[2].split("\n")[3].gsub("予約番号:", ""),
418
+ payment_on_cash: cells[3].gsub("円", "").to_i,
419
+ member_name: cells[4].split("\n")[0],
420
+ guest_name: cells[4].split("\n")[1],
421
+ guest_tel: cells[4].split("\n")[2].gsub("(", "").gsub(")", ""),
422
+ point: point
423
+ }
424
+ end
425
+ puts "saved:#{@reservation_date}" if RakutenReservation.create(@reservation_date).valid?
426
+ rescue StandardError => e
427
+ puts e
428
+ end
429
+ end
430
+ end
431
+ @driver.quit
432
+ end
433
+
434
+ def daily_data_past
435
+ @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[2]/tbody/tr[1]/td[1]/table/tbody/tr/td[3]/a/img").click
436
+ @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[5]/tbody/tr[2]/td[1]/table/tbody/tr[3]/td/table/tbody/tr/td[1]/input").click
437
+ sleep 3
438
+ (0..13).each do |i|
439
+ select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_date"))
440
+ select.select_by(:index, i)
441
+ display_data = @driver.find_element(:xpath, '//input[@value = "表示"]')
442
+ display_data.click
443
+ rows = @driver.find_elements(:xpath, "//tr")
444
+ rows[27..58].each do |row|
445
+ cells = row.find_elements(:css, "td[align=RIGHT]").map { |a| a.text.strip.gsub(",", "") }
446
+ break unless cells[5] && cells[5].to_i > 1
447
+ @output_hash = {
448
+ date: cells[0],
449
+ reservation_sales: cells[1],
450
+ access_ppl: cells[2],
451
+ cvr: cells[3],
452
+ reservation_unit_price: cells[4],
453
+ pv: cells[5],
454
+ pc_retained: cells[6],
455
+ pc_deliveries: cells[7],
456
+ pc_total_delivered: cells[8],
457
+ sp_retained: cells[9],
458
+ sp_deliveries: cells[10],
459
+ sp_total_delivered: cells[11]
460
+ }
461
+ puts "saved in DB:#{@output_hash}" if RakutenDaily.create(@output_hash).valid?
462
+ end
463
+ end
464
+ @driver.quit
465
+ rescue StandardError => e
466
+ @driver.quit
467
+ puts e.to_json
468
+ end
469
+
470
+ def daily_data_update
471
+ green_tab = @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[2]/tbody/tr[1]/td[1]/table/tbody/tr/td[3]/a/img").click
472
+ karute_button = @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[5]/tbody/tr[2]/td[1]/table/tbody/tr[3]/td/table/tbody/tr/td[1]/input").click
473
+ sleep 3
474
+ if Time.now.day == 1
475
+ else
476
+ value = if Time.now.month.to_s.size == 2
477
+ Time.now.year.to_s + Time.now.month.to_s + "01"
478
+ else
479
+ Time.now.year.to_s + "0" + Time.now.month.to_s + "01"
480
+ end
481
+ select = Selenium::WebDriver::Support::Select.new(@driver.find_element(:name, "f_date"))
482
+ select.select_by(:value, value)
483
+ end
484
+ display_data = @driver.find_element(:xpath, '//input[@value = "表示"]').click
485
+ rows = @driver.find_elements(:xpath, "//tr")
486
+ rows[27..58].each do |row|
487
+ cells = row.find_elements(:css, "td[align=RIGHT]").map { |a| a.text.strip.gsub(",", "") }
488
+ break unless cells[5] && cells[5].to_i > 1
489
+
490
+ @output_hash = {
491
+ "date" => cells[0],
492
+ "hotel_id" => @hotel.id,
493
+ "reservation_sales" => cells[1],
494
+ "access_ppl" => cells[2],
495
+ "cvr" => cells[3],
496
+ "reservation_unit_price" => cells[4],
497
+ "pv" => cells[5],
498
+ "pc_retained" => cells[6],
499
+ "pc_deliveries" => cells[7],
500
+ "pc_total_delivered" => cells[8],
501
+ "sp_retained" => cells[9],
502
+ "sp_deliveries" => cells[10],
503
+ "sp_total_delivered" => cells[11]
504
+ }
505
+ puts "saved in DB:#{@output_hash}" if RakutenDaily.create(@output_hash).valid?
506
+ end
507
+ @driver.quit
508
+ rescue StandardError => e
509
+ @driver.quit
510
+ end
511
+
512
+ def monthly_data_past
513
+ karute_button = @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[2]/tbody/tr[1]/td[1]/table/tbody/tr/td[3]/a/img").click
514
+ karute_page = @driver.find_element(:xpath, "/html/body/table[2]/tbody/tr/td[3]/table[5]/tbody/tr[2]/td[1]/table/tbody/tr[3]/td/table/tbody/tr/td[2]/input").click
515
+ month_karute = @driver.find_element(:xpath, "/html/body/center/table[1]/tbody/tr[2]/td/table/tbody/tr[2]/td/form/input[8]").click
516
+ rows = @driver.find_elements(:xpath, "//tr")
517
+ rows[19..31].each do |row|
518
+ cells = row.find_elements(:css, "td").map { |a| a.text.strip.gsub(",", "") }
519
+ break unless cells[9] && cells[9].to_i > 1
520
+
521
+ data = {
522
+ date: cells[0].gsub("/", "").to_s + "01",
523
+ hotel_id: Branch.find_by_rakuten_hotel_id(@config[:rakuten_hotel_id]).hotel_id,
524
+ reservation_sales: cells[1],
525
+ reservation_ppl: cells[2],
526
+ access_ppl: cells[3],
527
+ access_ppl_top_avg: cells[4],
528
+ cvr: cells[5],
529
+ cvr_top_avg: cells[6],
530
+ reservation_unit_price: cells[7],
531
+ reservation_unit_price_top_avg: cells[8],
532
+ pv: cells[9],
533
+ pv_top_avg: cells[10],
534
+ rmail_list_num: cells[11],
535
+ rmail_num: cells[12],
536
+ rmail_delivery_num: cells[13],
537
+ prize: cells[14]
538
+ }
539
+ puts "db saved : #{data}" if RakutenKaruteReservation.create(data).valid?
540
+ end
541
+ @driver.quit
542
+ rescue StandardError => e
543
+ puts e.to_json
544
+ @driver.quit
10
545
  end
11
546
  end
12
547
  end
@@ -29,13 +29,33 @@ module HotelPrice::Rakuten
29
29
  data
30
30
  end
31
31
 
32
+ def self.get_photo_num rakuten_hotel_id
33
+ driver = self.get_selenium_driver
34
+ driver.get "https://hotel.travel.rakuten.co.jp/hinfo/#{rakuten_hotel_id}/"
35
+ sleep 2
36
+ num = driver.find_element(:id, "navPht").text.gsub("写真・動画(", "").gsub(")", "").to_i
37
+ driver.quit
38
+ num
39
+ end
40
+
41
+ def self.get_bf_plan_num rakuten_hotel_id
42
+ driver = self.get_selenium_driver
43
+ driver.get "https://hotel.travel.rakuten.co.jp/hotelinfo/plan/#{rakuten_hotel_id}"
44
+ driver.find_element(:id, "focus1").click
45
+ driver.find_element(:id, "dh-squeezes-submit").click
46
+ sleep 30
47
+ plan_num = driver.find_elements(:class, "planThumb")
48
+ driver.quit
49
+ plan_num.size
50
+ end
51
+
32
52
  def self.get_selenium_driver
33
53
  # firefox_capabilities = Selenium::WebDriver::Remote::Capabilities.firefox
34
54
  # @driver = Selenium::WebDriver.for(:remote, url: "http://hub:4444/wd/hub", desired_capabilities: firefox_capabilities)
35
55
 
36
56
  options = Selenium::WebDriver::Firefox::Options.new
37
57
  options.add_argument("-headless")
38
- Selenium::WebDriver.for :firefox, options: options
58
+ Selenium::WebDriver.for :firefox#, options: options
39
59
  end
40
60
 
41
61
  end
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
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.6
4
+ version: 0.3.7
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-18 00:00:00.000000000 Z
12
+ date: 2020-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -95,6 +95,20 @@ dependencies:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
97
  version: '3.141'
98
+ - !ruby/object:Gem::Dependency
99
+ name: json
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: 2.3.0
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: 2.3.0
98
112
  description: 'Empower World Travel Information Technology '
99
113
  email:
100
114
  - fumitake.kawasaki@el-soul.com
@@ -124,6 +138,7 @@ files:
124
138
  - lib/hotel_price/agoda/agoda_scraper.rb
125
139
  - lib/hotel_price/booking.rb
126
140
  - lib/hotel_price/booking/booking_scraper.rb
141
+ - lib/hotel_price/configuration.rb
127
142
  - lib/hotel_price/expedia.rb
128
143
  - lib/hotel_price/expedia/expedia_scraper.rb
129
144
  - lib/hotel_price/jalan.rb