hotel_price 0.5.1 → 0.5.2

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: 721f3ad16dfb1b86f930d6f9f420590ed1774f56653f1793ed2267deb8668ded
4
- data.tar.gz: 7b4096b1eba821639226712dae8f36ba1adc09a1e01cc5bc756f2b3a0f60dc9b
3
+ metadata.gz: 8fd231f11180111d3ad02831039cb550616f229187d094904e319283ad5edddf
4
+ data.tar.gz: af6b0f219ea03e0e3ef0cf261eb8ea760cb3fadae129144c2512e631907c1bf6
5
5
  SHA512:
6
- metadata.gz: 1acfb4cecec62bf16f2e8b5c167151f15f2dbb99757b0a44f4771091f98cb80820e57cbb9e36cd4df1d8693eba74747d11ca8758f9c4b1eee7457f45d023fc6b
7
- data.tar.gz: d372e2383be49bee1a3ae3db191abfea5806208d6eb7d3b36bd4cd393db3552f425b48c36bbe94e086f4735ee932116cf9a047ef47c584cf83c26dd5aa76d99e
6
+ metadata.gz: b961c2ed9421d09648903cd4adc1c81fa42f88017361dca002e6e9d13c45baf7c51339dd38470062eec3b1257e8b2a4ad56f039cd2938af25110ebf351695ee0
7
+ data.tar.gz: d57619eb97f7fb8ad33d69ba22653201fe607f4ea81d7f65fd0a608e890339405511979538c243fc5b5ba151f553dbcf722c4261f034f0c3e9ef93b586861d41
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotel_price (0.4.9)
4
+ hotel_price (0.5.1)
5
5
  activesupport (~> 6.0.2.1)
6
6
  json (~> 2.3.0)
7
7
  nokogiri (~> 1.10.9)
data/lib/hotel_price.rb CHANGED
@@ -36,7 +36,7 @@ module HotelPrice
36
36
  end
37
37
  end
38
38
 
39
- private
39
+ protected
40
40
 
41
41
  def self.get_selenium_driver(mode = 0)
42
42
  case mode
@@ -52,6 +52,8 @@ module HotelPrice
52
52
  end
53
53
  end
54
54
 
55
+ private
56
+
55
57
  class Configuration
56
58
  # Agoda API key
57
59
  # @param [String]
@@ -2,12 +2,12 @@ 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)
5
+ def self.get_price(agoda_hotel_id, checkin_date, num_adults, mode = 0)
6
6
  date = DateTime.now.strftime("%Y-%m-%d")
7
7
 
8
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
- driver = self.get_selenium_driver mode
10
+ driver = HotelPrice.get_selenium_driver mode
11
11
  driver.get(url)
12
12
  sleep 2
13
13
 
@@ -43,7 +43,5 @@ module HotelPrice::Agoda
43
43
  return "" if num_adults.to_i <= 1
44
44
  "adults=#{num_adults}"
45
45
  end
46
-
47
-
48
46
  end
49
47
  end
@@ -2,12 +2,13 @@ require "date"
2
2
 
3
3
  module HotelPrice::Booking
4
4
  class BookingScraper
5
- def self.get_price(booking_hotel_id, checkin_date, num_adults)
5
+
6
+ def self.get_price(booking_hotel_id, checkin_date, num_adults, mode = 0)
6
7
  date = DateTime.now.strftime("%Y-%m-%d")
7
8
 
8
9
  query_string = make_query_string(checkin_date.to_s, num_adults)
9
10
  url = "https://www.booking.com/hotel/jp/#{booking_hotel_id}.ja.html?#{query_string}"
10
- driver = self.get_selenium_driver mode
11
+ driver = HotelPrice.get_selenium_driver mode
11
12
  driver.get(url)
12
13
  sleep 2
13
14
 
@@ -2,12 +2,12 @@ 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)
5
+ def self.get_price(expedia_hotel_id, checkin_date, num_adults, mode = 0)
6
6
  date = DateTime.now.strftime("%Y-%m-%d")
7
7
 
8
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
- driver = self.get_selenium_driver mode
10
+ driver = HotelPrice.get_selenium_driver mode
11
11
  driver.get(url)
12
12
  sleep 2
13
13
 
@@ -32,12 +32,11 @@ module HotelPrice::Expedia
32
32
  "#{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
33
  end
34
34
 
35
-
36
35
  def self.make_date_args checkin_date
37
36
  Date.parse checkin_date rescue return ""
38
37
  t = Date.parse(checkin_date)
39
38
  checkin_arg = t.strftime("chkin=%Y-%m-%d")
40
- checkout_arg = (t+1).strftime("chkout=%Y-%m-%d")
39
+ checkout_arg = (t + 1).strftime("chkout=%Y-%m-%d")
41
40
  "#{checkin_arg}&#{checkout_arg}"
42
41
  end
43
42
 
@@ -46,4 +45,4 @@ module HotelPrice::Expedia
46
45
  "rm1=a#{num_adults}"
47
46
  end
48
47
  end
49
- end
48
+ end
@@ -6,7 +6,7 @@ module HotelPrice::Jalan
6
6
  query_string = make_query_string(checkin_date.to_s, num_adults)
7
7
  url = "https://www.jalan.net/yad#{jalan_hotel_id}/plan/?screenId=UWW3101&yadNo=#{jalan_hotel_id}&#{query_string}"
8
8
  puts url
9
- driver = self.get_selenium_driver mode
9
+ driver = HotelPrice.get_selenium_driver mode
10
10
  driver.get(url)
11
11
  sleep 2
12
12
  @price_box = []
@@ -20,11 +20,11 @@ module HotelPrice::Jalan
20
20
  room_name: e.find_element(class_name: "p-searchResultItem__planName").text,
21
21
  plan_name: f.find_element(class_name: "p-planCassette__header").text
22
22
  }
23
- rescue
23
+ rescue StandardError
24
24
  end
25
25
  end
26
- @price_box.sort_by { |a, b, c| c }.reverse.first
27
- rescue
26
+ @price_box.sort_by { |_a, _b, c| c }.reverse.first
27
+ rescue StandardError
28
28
  { date: date, min_price: 0 }
29
29
  end
30
30
 
@@ -44,4 +44,4 @@ module HotelPrice::Jalan
44
44
  "adultNum=#{num_adults}"
45
45
  end
46
46
  end
47
- end
47
+ end
@@ -9,7 +9,7 @@ module HotelPrice::Rakuten
9
9
  mode: params[:mode] ||= 0
10
10
  }
11
11
  @wait = Selenium::WebDriver::Wait.new(timeout: 100)
12
- @driver = get_selenium_driver @config[:mode]
12
+ @driver = self.get_selenium_driver @config[:mode]
13
13
  if @config[:chain]
14
14
  go_to_management_page_chain
15
15
  else
@@ -17,19 +17,6 @@ module HotelPrice::Rakuten
17
17
  end
18
18
  end
19
19
 
20
- def get_selenium_driver(mode = 0)
21
- if mode == 1
22
- firefox_capabilities = Selenium::WebDriver::Remote::Capabilities.firefox
23
- Selenium::WebDriver.for(:remote, url: "http://selenium-hub:4444/wd/hub", desired_capabilities: firefox_capabilities)
24
- elsif mode == 2
25
- Selenium::WebDriver.for :firefox
26
- else
27
- options = Selenium::WebDriver::Firefox::Options.new
28
- options.add_argument("-headless")
29
- Selenium::WebDriver.for :firefox, options: options
30
- end
31
- end
32
-
33
20
  def go_to_management_page_chain
34
21
  @driver.get "https://manage.travel.rakuten.co.jp/portal/inn/ry_group.main"
35
22
  @driver.find_element(:name, "f_id").send_keys @config[:login_id].to_s
@@ -8,7 +8,7 @@ module HotelPrice::Rakuten
8
8
 
9
9
  query_string = make_query_string(checkin_date.to_s, num_adults)
10
10
  url = "https://hotel.travel.rakuten.co.jp/hotelinfo/plan/#{rakuten_hotel_id}?#{query_string}"
11
- driver = self.get_selenium_driver mode
11
+ driver = HotelPrice.get_selenium_driver mode
12
12
  driver.get(url)
13
13
  sleep 2
14
14
  driver.find_elements(class_name: "planThumb").first rescue return ""
@@ -18,7 +18,7 @@ module HotelPrice::Rakuten
18
18
  room_name = first_plan.find_element(tag_name: "h6").text
19
19
  plan_name = first_plan.find_element(tag_name: "h4").text
20
20
  { date: date, min_price: price, hotel_name: hotel_name, room_name: room_name, plan_name: plan_name }
21
- rescue
21
+ rescue StandardError
22
22
  { date: date, min_price: 0 }
23
23
  end
24
24
 
@@ -41,10 +41,9 @@ module HotelPrice::Rakuten
41
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
42
  end
43
43
 
44
-
45
44
  def self.review rakuten_hotel_id, mode = 0
46
- driver = self.get_selenium_driver mode
47
- driver.get("https://travel.rakuten.co.jp/HOTEL/#{rakuten_hotel_id.to_s}/review.html")
45
+ driver = HotelPrice.get_selenium_driver mode
46
+ driver.get("https://travel.rakuten.co.jp/HOTEL/#{rakuten_hotel_id}/review.html")
48
47
  sleep 2
49
48
  comment_area = driver.find_elements(:class_name, "commentBox")
50
49
  data = comment_area.map do |f|
@@ -53,12 +52,12 @@ module HotelPrice::Rakuten
53
52
  generation = 0
54
53
  gender = ""
55
54
  else
56
- username = f.find_element(class_name: "user").text.match(/(^.+ )/).to_s.strip
57
- generation = f.find_element(class_name: "user").text.match(/\[.+代/).to_s.gsub("[","").gsub("代", "")
55
+ username = f.find_element(class_name: "user").text.match(/(^.+ )/).to_s.strip
56
+ generation = f.find_element(class_name: "user").text.match(/\[.+代/).to_s.gsub("[", "").gsub("代", "")
58
57
  gender = f.find_element(class_name: "user").text.match(/\/../).to_s.gsub("/", "")
59
58
  end
60
59
  {
61
- date: f.find_element(class_name: "time").text.gsub("年","").gsub("月", "").gsub("日", ""),
60
+ date: f.find_element(class_name: "time").text.gsub("年", "").gsub("月", "").gsub("日", ""),
62
61
  rate: f.find_element(class_name: "rate").text,
63
62
  username: username,
64
63
  generation: generation,
@@ -72,7 +71,7 @@ module HotelPrice::Rakuten
72
71
  end
73
72
 
74
73
  def self.get_photo_num rakuten_hotel_id, mode = 0
75
- driver = self.get_selenium_driver mode
74
+ driver = HotelPrice.get_selenium_driver mode
76
75
  driver.get "https://hotel.travel.rakuten.co.jp/hinfo/#{rakuten_hotel_id}/"
77
76
  sleep 2
78
77
  num = driver.find_element(:id, "navPht").text.gsub("写真・動画(", "").gsub(")", "").to_i
@@ -81,7 +80,7 @@ module HotelPrice::Rakuten
81
80
  end
82
81
 
83
82
  def self.get_bf_plan_num rakuten_hotel_id, mode = 0
84
- driver = self.get_selenium_driver mode
83
+ driver = HotelPrice.get_selenium_driver mode
85
84
  driver.get "https://hotel.travel.rakuten.co.jp/hotelinfo/plan/#{rakuten_hotel_id}"
86
85
  driver.find_element(:id, "focus1").click
87
86
  driver.find_element(:id, "dh-squeezes-submit").click
@@ -92,7 +91,7 @@ module HotelPrice::Rakuten
92
91
  end
93
92
 
94
93
  def self.get_dayuse_plan_num rakuten_hotel_id, mode = 0
95
- driver = self.get_selenium_driver mode
94
+ driver = HotelPrice.get_selenium_driver mode
96
95
  driver.get "https://hotel.travel.rakuten.co.jp/hotelinfo/plan/#{rakuten_hotel_id}"
97
96
  sleep 10
98
97
  driver.find_element(:id, "du-radio").click
@@ -104,17 +103,17 @@ module HotelPrice::Rakuten
104
103
  end
105
104
 
106
105
  def self.get_detail_class_code rakuten_hotel_id, mode = 0
107
- driver = self.get_selenium_driver mode
106
+ driver = HotelPrice.get_selenium_driver mode
108
107
  driver.get "https://hotel.travel.rakuten.co.jp/hinfo/?f_no=#{rakuten_hotel_id}"
109
108
  {
110
109
  status: "found",
111
110
  detail_class_code: driver.find_element(id: "breadcrumbs-detail").attribute("href").match(/\/.\./).to_s.gsub("/", "").gsub(".", "")
112
111
  }
113
- rescue
112
+ rescue StandardError
114
113
  {
115
114
  status: "not_found",
116
115
  detail_class_code: ""
117
116
  }
118
117
  end
119
118
  end
120
- end
119
+ end
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
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.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fumitake Kawasaki