hotel_price 0.5.7 → 0.5.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: 7a238e76090c742fb9853184bdc3af2b062bfec971635d7e25944e96ab028b60
4
- data.tar.gz: 9f1b26e87a46a327bc66588298d3ad1c599519bbd2ef8a1fc0361970c4f5cc87
3
+ metadata.gz: 1f8327ee6d730dcdba0c4858ce602ec2ae1d38f8201509433404e1639e232012
4
+ data.tar.gz: 0dfb793cdca1fe7d47d15a4f070e6d8932555ca8abb158bdd77082951d36faeb
5
5
  SHA512:
6
- metadata.gz: 69960789ac56c5f8a08251c7c492dfe6672e3d0925b574c3bc1efb206fb0832b5ecbac7796ba141fe9bbcc12159b1a7720b28aeca5b1ef19360c247080a85403
7
- data.tar.gz: 8a4d5c362aae20d2081f1f2945a6418607738578bca532139688234ce9f4b81ecc73c334dd9805394a2efd41ec7c40efc4e6aafce712fe6ff677fc4ccffe2049
6
+ metadata.gz: 0e42dd98efc0a3b0777e13551e45fd226cd43f48cb9a886efdbcab1e42f20fd8a2194af525efb82b9535e5e9c1b9760711826c32b1558e3a777197bf3bf8e3f3
7
+ data.tar.gz: 25dd6df2d2f139027ca13b5f0f3cb68dc7698c6786785b7c85b584c1a3db0fd2ffca58c5c8881286093bb4fcc6bffaeda7c00177f085451f612aae8dd397878c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotel_price (0.5.6)
4
+ hotel_price (0.5.8)
5
5
  activesupport (~> 6.0.2.1)
6
6
  json (~> 2.3.0)
7
7
  nokogiri (~> 1.10.9)
data/README.md CHANGED
@@ -31,7 +31,7 @@ Rakuten Travel API Reference : https://webservice.rakuten.co.jp/api/simplehotels
31
31
 
32
32
 
33
33
  ```ruby
34
- hotel = HotelPrice::Rakuten::RakutenScraper.new(
34
+ hotel = HotelPrice::Rakuten::RakutenAPI.new(
35
35
  rakuten_hotel_id: "128552",
36
36
  rakuten_api_key: "api_key"
37
37
  )
@@ -38,12 +38,12 @@ module HotelPrice
38
38
 
39
39
  protected
40
40
 
41
- def self.get_selenium_driver(mode = 0)
41
+ def self.get_selenium_driver(mode = :chrome)
42
42
  case mode
43
- when 1
43
+ when :firefox_remote_capabilities
44
44
  firefox_capabilities = Selenium::WebDriver::Remote::Capabilities.firefox
45
45
  Selenium::WebDriver.for(:remote, url: "http://hub:4444/wd/hub", desired_capabilities: firefox_capabilities)
46
- when 2
46
+ when :firefox
47
47
  Selenium::WebDriver.for :firefox
48
48
  else
49
49
  options = Selenium::WebDriver::Chrome::Options.new
@@ -61,6 +61,7 @@ module HotelPrice
61
61
  # Agoda API key
62
62
  # @param [String]
63
63
  attr_accessor :agoda_api_key
64
+ attr_accessor :selenium_driver
64
65
 
65
66
  def initialize
66
67
  @agoda_api_key = nil
@@ -2,12 +2,18 @@ require "date"
2
2
 
3
3
  module HotelPrice::Agoda
4
4
  class AgodaScraper
5
- def self.get_price(agoda_hotel_id, checkin_date, num_adults, mode = 0)
5
+ @mode
6
+
7
+ def initialize(mode = :chrome)
8
+ @mode = mode
9
+ end
10
+
11
+ def get_price(agoda_hotel_id, checkin_date, num_adults)
6
12
  date = DateTime.now.strftime("%Y-%m-%d")
7
13
 
8
14
  query_string = make_query_string(checkin_date.to_s, num_adults)
9
15
  url = "https://www.agoda.com/ja-jp/#{agoda_hotel_id}.html?#{query_string}"
10
- driver = HotelPrice.get_selenium_driver mode
16
+ driver = HotelPrice.get_selenium_driver @mode
11
17
  driver.get(url)
12
18
  sleep 2
13
19
 
@@ -26,20 +32,20 @@ module HotelPrice::Agoda
26
32
  { checkin_date: checkin_date, min_price: price, hotel_name: hotel_name, room_name: room_name }
27
33
  end
28
34
 
29
- def self.make_query_string(checkin_date, num_adults)
35
+ def make_query_string(checkin_date, num_adults)
30
36
  cd_args = make_date_args checkin_date
31
37
  na_args = make_num_adults_arg num_adults
32
38
  "#{cd_args}&#{na_args}&rooms=1&travellerType=-1"
33
39
  end
34
40
 
35
- def self.make_date_args checkin_date
41
+ def make_date_args checkin_date
36
42
  Date.parse checkin_date rescue return ""
37
43
  t = Date.parse(checkin_date)
38
44
  checkin_arg = t.strftime("checkIn=%Y-%m-%d")
39
45
  "#{checkin_arg}&los=2"
40
46
  end
41
47
 
42
- def self.make_num_adults_arg num_adults
48
+ def make_num_adults_arg num_adults
43
49
  return "" if num_adults.to_i <= 1
44
50
  "adults=#{num_adults}"
45
51
  end
@@ -3,12 +3,18 @@ require "date"
3
3
  module HotelPrice::Booking
4
4
  class BookingScraper
5
5
 
6
- def self.get_price(booking_hotel_id, checkin_date, num_adults, mode = 0)
6
+ @mode
7
+
8
+ def initialize(mode = :chrome)
9
+ @mode = mode
10
+ end
11
+
12
+ def get_price(booking_hotel_id, checkin_date, num_adults)
7
13
  date = DateTime.now.strftime("%Y-%m-%d")
8
14
 
9
15
  query_string = make_query_string(checkin_date.to_s, num_adults)
10
16
  url = "https://www.booking.com/hotel/jp/#{booking_hotel_id}.ja.html?#{query_string}"
11
- driver = HotelPrice.get_selenium_driver mode
17
+ driver = HotelPrice.get_selenium_driver @mode
12
18
  driver.get(url)
13
19
  sleep 2
14
20
 
@@ -29,13 +35,13 @@ module HotelPrice::Booking
29
35
  { checkin_date: checkin_date, min_price: price, hotel_name: hotel_name, room_name: room_name }
30
36
  end
31
37
 
32
- def self.make_query_string(checkin_date, num_adults)
38
+ def make_query_string(checkin_date, num_adults)
33
39
  cd_args = make_date_args checkin_date
34
40
  na_args = make_num_adults_arg num_adults
35
41
  "#{cd_args}&#{na_args}&dist=0&do_availability_check=1&hp_avform=1&hp_group_set=0&no_rooms=1&origin=hp&sb_price_type=total&src=hotel&tab=1&type=total&lang=ja&selected_currency=JPY"
36
42
  end
37
43
 
38
- def self.make_date_args checkin_date
44
+ def make_date_args checkin_date
39
45
  Date.parse checkin_date rescue return ""
40
46
  t = Date.parse(checkin_date)
41
47
  checkin_arg = t.strftime("checkin_monthday=%d&checkin_year_month=%Y-%m")
@@ -43,7 +49,7 @@ module HotelPrice::Booking
43
49
  "#{checkin_arg}&#{checkout_arg}"
44
50
  end
45
51
 
46
- def self.make_num_adults_arg num_adults
52
+ def make_num_adults_arg num_adults
47
53
  return "" if num_adults.to_i <= 1
48
54
  "group_adults=#{num_adults}&group_children=0"
49
55
  end
@@ -2,12 +2,18 @@ require "date"
2
2
 
3
3
  module HotelPrice::Expedia
4
4
  class ExpediaScraper
5
- def self.get_price(expedia_hotel_id, checkin_date, num_adults, mode = 0)
5
+ @mode
6
+
7
+ def initialize(mode = :chrome)
8
+ @mode = mode
9
+ end
10
+
11
+ def get_price(expedia_hotel_id, checkin_date, num_adults)
6
12
  date = DateTime.now.strftime("%Y-%m-%d")
7
13
 
8
14
  query_string = make_query_string(checkin_date.to_s, num_adults)
9
15
  url = "https://www.expedia.co.jp/ja/#{expedia_hotel_id}.Hotel-Information?#{query_string}"
10
- driver = HotelPrice.get_selenium_driver mode
16
+ driver = HotelPrice.get_selenium_driver @mode
11
17
  driver.get(url)
12
18
  sleep 2
13
19
 
@@ -26,13 +32,13 @@ module HotelPrice::Expedia
26
32
  { checkin_date: checkin_date, min_price: price, hotel_name: hotel_name, room_name: room_name }
27
33
  end
28
34
 
29
- def self.make_query_string(checkin_date, num_adults)
35
+ def make_query_string(checkin_date, num_adults)
30
36
  cd_args = make_date_args checkin_date
31
37
  na_args = make_num_adults_arg num_adults
32
38
  "#{cd_args}&#{na_args}&x_pwa=1&rfrr=HSR&pwa_ts=1583335742618&swpToggleOn=true&regionId=3250&destination=Sapporo%2C+Hokkaido%2C+Japan&destType=MARKET&neighborhoodId=6290332&selected=5224778&sort=recommended&top_dp=5686&top_cur=JPY"
33
39
  end
34
40
 
35
- def self.make_date_args checkin_date
41
+ def make_date_args checkin_date
36
42
  Date.parse checkin_date rescue return ""
37
43
  t = Date.parse(checkin_date)
38
44
  checkin_arg = t.strftime("chkin=%Y-%m-%d")
@@ -40,7 +46,7 @@ module HotelPrice::Expedia
40
46
  "#{checkin_arg}&#{checkout_arg}"
41
47
  end
42
48
 
43
- def self.make_num_adults_arg num_adults
49
+ def make_num_adults_arg num_adults
44
50
  return "" if num_adults.to_i <= 1
45
51
  "rm1=a#{num_adults}"
46
52
  end
@@ -1,11 +1,17 @@
1
1
  module HotelPrice::Jalan
2
2
  class JalanScraper
3
- def self.get_price(jalan_hotel_id, checkin_date, num_adults, mode = 0)
3
+ @mode
4
+
5
+ def initialize(mode = :chrome)
6
+ @mode = mode
7
+ end
8
+
9
+ def get_price(jalan_hotel_id, checkin_date, num_adults)
4
10
  date = DateTime.now.strftime("%Y-%m-%d")
5
11
 
6
12
  query_string = make_query_string(checkin_date.to_s, num_adults)
7
13
  url = "https://www.jalan.net/yad#{jalan_hotel_id}/plan/?screenId=UWW3101&yadNo=#{jalan_hotel_id}&#{query_string}"
8
- driver = HotelPrice.get_selenium_driver mode
14
+ driver = HotelPrice.get_selenium_driver @mode
9
15
  driver.get(url)
10
16
  sleep 2
11
17
  @price_box = []
@@ -28,18 +34,18 @@ module HotelPrice::Jalan
28
34
  { date: date, min_price: 0 }
29
35
  end
30
36
 
31
- def self.make_query_string(checkin_date, num_adults)
37
+ def make_query_string(checkin_date, num_adults)
32
38
  cd_args = make_date_args checkin_date
33
39
  na_args = make_num_adults_arg num_adults
34
40
  "rootCd=7701&callbackHistFlg=1&contHideFlg=1&reSearchFlg=1&roomCrack=100000&smlCd=121108&distCd=01&#{cd_args}&stayCount=1&roomCount=1&#{na_args}&minPrice=0&maxPrice=999999"
35
41
  end
36
42
 
37
- def self.make_date_args checkin_date
43
+ def make_date_args checkin_date
38
44
  Date.parse checkin_date rescue return ""
39
45
  Date.parse(checkin_date).strftime("stayYear=%Y&stayMonth=%m&stayDay=%d")
40
46
  end
41
47
 
42
- def self.make_num_adults_arg num_adults
48
+ def make_num_adults_arg num_adults
43
49
  return "" if num_adults.to_i < 1
44
50
  "adultNum=#{num_adults}"
45
51
  end
@@ -6,7 +6,7 @@ module HotelPrice::Rakuten
6
6
  login_pw: params[:login_pw],
7
7
  chain: params[:chain] ||= false,
8
8
  rakuten_hotel_id: params[:rakuten_hotel_id] ||= 0,
9
- mode: params[:mode] ||= 0
9
+ mode: params[:mode] ||= :chrome
10
10
  }
11
11
  @wait = Selenium::WebDriver::Wait.new(timeout: 100)
12
12
  @driver = HotelPrice.get_selenium_driver @config[:mode]
@@ -3,12 +3,18 @@ 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)
6
+ @mode
7
+
8
+ def initialize(mode = :chrome)
9
+ @mode = mode
10
+ end
11
+
12
+ def get_price(rakuten_hotel_id, checkin_date, num_adults)
7
13
  date = DateTime.now.strftime("%Y-%m-%d")
8
14
 
9
15
  query_string = make_query_string(checkin_date.to_s, num_adults)
10
16
  url = "https://hotel.travel.rakuten.co.jp/hotelinfo/plan/#{rakuten_hotel_id}?#{query_string}"
11
- driver = HotelPrice.get_selenium_driver mode
17
+ driver = HotelPrice.get_selenium_driver @mode
12
18
  driver.get(url)
13
19
  sleep 2
14
20
  driver.find_elements(class_name: "planThumb").first rescue return ""
@@ -22,13 +28,13 @@ module HotelPrice::Rakuten
22
28
  { date: date, min_price: 0 }
23
29
  end
24
30
 
25
- def self.make_query_string(checkin_date, num_adults)
31
+ def make_query_string(checkin_date, num_adults)
26
32
  cd_args = make_date_args checkin_date
27
33
  na_args = make_num_adults_arg num_adults
28
34
  "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
35
  end
30
36
 
31
- def self.make_date_args checkin_date
37
+ def make_date_args checkin_date
32
38
  Date.parse checkin_date rescue return ""
33
39
  t = Date.parse(checkin_date)
34
40
  checkin_arg = t.strftime("f_hi1=%d&f_tuki1=%m&f_nen1=%Y")
@@ -36,13 +42,13 @@ module HotelPrice::Rakuten
36
42
  "#{checkin_arg}&#{checkout_arg}"
37
43
  end
38
44
 
39
- def self.make_num_adults_arg num_adults
45
+ def make_num_adults_arg num_adults
40
46
  return "" if num_adults.to_i <= 1
41
47
  "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
48
  end
43
49
 
44
- def self.review rakuten_hotel_id, mode = 0
45
- driver = HotelPrice.get_selenium_driver mode
50
+ def review rakuten_hotel_id
51
+ driver = HotelPrice.get_selenium_driver @mode
46
52
  driver.get("https://travel.rakuten.co.jp/HOTEL/#{rakuten_hotel_id}/review.html")
47
53
  sleep 2
48
54
  comment_area = driver.find_elements(:class_name, "commentBox")
@@ -70,8 +76,8 @@ module HotelPrice::Rakuten
70
76
  data
71
77
  end
72
78
 
73
- def self.get_photo_num rakuten_hotel_id, mode = 0
74
- driver = HotelPrice.get_selenium_driver mode
79
+ def get_photo_num rakuten_hotel_id
80
+ driver = HotelPrice.get_selenium_driver @mode
75
81
  driver.get "https://hotel.travel.rakuten.co.jp/hinfo/#{rakuten_hotel_id}/"
76
82
  sleep 2
77
83
  num = driver.find_element(:id, "navPht").text.gsub("写真・動画(", "").gsub(")", "").to_i
@@ -79,8 +85,8 @@ module HotelPrice::Rakuten
79
85
  num
80
86
  end
81
87
 
82
- def self.get_bf_plan_num rakuten_hotel_id, mode = 0
83
- driver = HotelPrice.get_selenium_driver mode
88
+ def get_bf_plan_num rakuten_hotel_id
89
+ driver = HotelPrice.get_selenium_driver @mode
84
90
  driver.get "https://hotel.travel.rakuten.co.jp/hotelinfo/plan/#{rakuten_hotel_id}"
85
91
  driver.find_element(:id, "focus1").click
86
92
  driver.find_element(:id, "dh-squeezes-submit").click
@@ -90,20 +96,17 @@ module HotelPrice::Rakuten
90
96
  plan_num.size
91
97
  end
92
98
 
93
- def self.get_dayuse_plan_num rakuten_hotel_id, mode = 0
94
- driver = HotelPrice.get_selenium_driver mode
95
- driver.get "https://hotel.travel.rakuten.co.jp/hotelinfo/plan/#{rakuten_hotel_id}"
96
- sleep 5
97
- driver.find_element(:id, "du-radio").click
98
- driver.find_element(:id, "dh-submit").click
99
+ def get_dayuse_plan_num rakuten_hotel_id
100
+ driver = HotelPrice.get_selenium_driver @mode
101
+ driver.get "https://hotel.travel.rakuten.co.jp/hotelinfo/dayuse/?f_no=#{rakuten_hotel_id}"
99
102
  sleep 5
100
103
  plan_num = driver.find_elements(:class, "planThumb")
101
104
  driver.quit
102
105
  plan_num.size
103
106
  end
104
107
 
105
- def self.get_detail_class_code rakuten_hotel_id, mode = 0
106
- driver = HotelPrice.get_selenium_driver mode
108
+ def get_detail_class_code rakuten_hotel_id
109
+ driver = HotelPrice.get_selenium_driver @mode
107
110
  driver.get "https://hotel.travel.rakuten.co.jp/hinfo/?f_no=#{rakuten_hotel_id}"
108
111
  {
109
112
  status: "found",
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.5.7"
2
+ VERSION = "0.5.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.5.7
4
+ version: 0.5.9
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-04-27 00:00:00.000000000 Z
12
+ date: 2020-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler