hotel_price 0.4.8 → 0.4.9

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: 3b4e2665fa91d8978891c2405c4fc6c1d7125a7c78a86536b15aec75afd0af76
4
- data.tar.gz: f92fb54d39ee36be8b38bdf1004e92a5c5c2021f837ea3a549aad76f354d79f4
3
+ metadata.gz: a4877dd06abfc1db17f1eceee5c0762b6ce11f7244a5ee732b19bc6f32e8202c
4
+ data.tar.gz: 820fea4b1ca11ee555e97d3cd93091e4331e0fb5564717bce5795994897519db
5
5
  SHA512:
6
- metadata.gz: 7352f7ec8c68bb93d3d5b1965024113cc4c280754b5876cf99269a791746359e72ef65de27e178d47612ff28d7974084dca81ac5b05c687c97cfe97e63c183d0
7
- data.tar.gz: 972aed1c31307f1cd1facb6e897427fab37516e688fced73a2d51bf18293e36dc374c6b2d2c3660b9cc9f8eba1181f7be7b730eb36362f333da9e363efbb22fc
6
+ metadata.gz: 936d4d0452a487c9564b7d00af0035cdff16d8c24880a86fa588789bcdd6b512be74f5714814cdd8816537b64336dcc886a3243ca5e886fc1be0c7a8175a9c1e
7
+ data.tar.gz: 57a58b1c32df9f73494a9aa8174fc9afb1c6ab87fa948a681826d02160195f6c061cd0d419e4cee2b42c8c189fdc7b8def589a1f88817367310a1af3873ac02f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotel_price (0.4.5)
4
+ hotel_price (0.4.8)
5
5
  activesupport (~> 6.0.2.1)
6
6
  json (~> 2.3.0)
7
7
  nokogiri (~> 1.10.9)
@@ -165,9 +165,11 @@ module HotelPrice::Rakuten
165
165
 
166
166
  def get_area_rank
167
167
  body = get_page_num
168
+ puts body
168
169
  (1..body[:page_num]).each do |i|
169
170
  body[:page_num] = i
170
171
  rank = search_ranking(body)
172
+ puts rank
171
173
  return rank if rank[:status] == "found"
172
174
  end
173
175
  { status: "not_found" }
@@ -3,6 +3,45 @@ module HotelPrice::Rakuten
3
3
  ## mode 1 - docker selenium
4
4
  ## mode 2 - debug
5
5
  class RakutenScraper
6
+ def self.get_price(rakuten_hotel_id, checkin_date, num_adults, mode = 0)
7
+ date = DateTime.now.strftime("%Y-%m-%d")
8
+
9
+ query_string = make_query_string(checkin_date.to_s, num_adults)
10
+ url = "https://hotel.travel.rakuten.co.jp/hotelinfo/plan/#{rakuten_hotel_id}?#{query_string}"
11
+ driver = self.get_selenium_driver mode
12
+ driver.get(url)
13
+ sleep 2
14
+ driver.find_elements(class_name: "planThumb").first rescue return ""
15
+ first_plan = driver.find_elements(class_name: "planThumb").first
16
+ hotel_name = driver.find_element(class_name: "rtconds").text
17
+ price = first_plan.find_element(class_name: "vPrice").text.delete("^0-9").to_i
18
+ room_name = first_plan.find_element(tag_name: "h6").text
19
+ plan_name = first_plan.find_element(tag_name: "h4").text
20
+ { date: date, min_price: price, hotel_name: hotel_name, room_name: room_name, plan_name: plan_name }
21
+ rescue
22
+ { date: date, min_price: 0 }
23
+ end
24
+
25
+ def self.make_query_string(checkin_date, num_adults)
26
+ cd_args = make_date_args checkin_date
27
+ na_args = make_num_adults_arg num_adults
28
+ "f_teikei=quick&f_hizuke=&f_hak=&f_dai=japan&f_chu=tokyo&f_shou=nishi&f_sai=&f_tel=&f_target_flg=&f_tscm_flg=&f_p_no=&f_custom_code=&f_search_type=&f_camp_id=&f_static=1&f_rm_equip=&#{cd_args}&f_heya_su=1&#{na_args}"
29
+ end
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("f_hi1=%d&f_tuki1=%m&f_nen1=%Y")
35
+ checkout_arg = (t + 1).strftime("f_hi2=%d&f_tuki2=%m&f_nen2=%Y")
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
+ "f_otona_su=#{num_adults}&f_kin2=0&f_kin=&f_s1=0&f_s2=0&f_y1=0&f_y2=0&f_y3=0&f_y4=0"
42
+ end
43
+
44
+
6
45
  def self.review rakuten_hotel_id, mode = 0
7
46
  driver = self.get_selenium_driver mode
8
47
  driver.get("https://travel.rakuten.co.jp/HOTEL/#{rakuten_hotel_id.to_s}/review.html")
@@ -78,7 +117,6 @@ module HotelPrice::Rakuten
78
117
  }
79
118
  end
80
119
 
81
-
82
120
  def self.get_selenium_driver(mode = 0)
83
121
  if mode == 1
84
122
  firefox_capabilities = Selenium::WebDriver::Remote::Capabilities.firefox
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.4.8"
2
+ VERSION = "0.4.9"
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.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fumitake Kawasaki